Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Nov 4, 2020
Embed
What would you like to do?
memo = []
memo.append(1) # f(1) = 1
memo.append(1) # f(2) = 1
def fibonacci(n):
if len(memo) > n:
return memo[n]
result = fibonacci(n-1) + fibonacci(n-2)
memo.append(result) # f(n) = f(n-1) + f(n-2)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment