mirror of
https://gitlab.com/mfocko/CodeWars.git
synced 2024-11-22 08:33:48 +01:00
12 lines
267 B
Python
12 lines
267 B
Python
fibonacci_memory = {}
|
|
|
|
def fibonacci(n):
|
|
if n in [0, 1]:
|
|
return n
|
|
|
|
if n not in fibonacci_memory:
|
|
value = fibonacci(n - 1) + fibonacci(n - 2)
|
|
fibonacci_memory[n] = value
|
|
return value
|
|
else:
|
|
return fibonacci_memory[n]
|