Skip to content

Instantly share code, notes, and snippets.

@imohitmayank
Last active April 16, 2019 18:07
Show Gist options
  • Save imohitmayank/898d14ad4284c74a1f3235b8762875a6 to your computer and use it in GitHub Desktop.
Save imohitmayank/898d14ad4284c74a1f3235b8762875a6 to your computer and use it in GitHub Desktop.
Fibonacci number - memoization
memory = {0: 0, 1: 1}
def fib(n):
if n in memory.keys():
return(memory[n])
else:
memory[n] = fib(n-1) + fib(n-2)
return memory[n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment