Last active
April 16, 2019 18:07
-
-
Save imohitmayank/898d14ad4284c74a1f3235b8762875a6 to your computer and use it in GitHub Desktop.
Fibonacci number - memoization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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