Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created November 4, 2020 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/e94f90006447864045dba53011132683 to your computer and use it in GitHub Desktop.
Save amankharwal/e94f90006447864045dba53011132683 to your computer and use it in GitHub Desktop.
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