1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 11:09:07 +01:00
CodeWars/5kyu/memoized_fibonacci/solution.py
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

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]