Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created November 4, 2020 12:16
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/a6cdebcf3178b6fb4a7503af3946aee1 to your computer and use it in GitHub Desktop.
Save amankharwal/a6cdebcf3178b6fb4a7503af3946aee1 to your computer and use it in GitHub Desktop.
def fibonacci(n):
memo = [1,1] # f(1) = 1, f(2) = 1
for i in range (2, n):
memo[i%2] = memo[0] + memo[1]
return memo[n%2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment