1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-22 16:43:46 +01:00
CodeWars/5kyu/memoized_fibonacci/solution.py

13 lines
267 B
Python
Raw Normal View History

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]