Created
March 24, 2020 15:54
-
-
Save hiepph/652f3988a08364456e2a17d96abf93b0 to your computer and use it in GitHub Desktop.
Fibonacci with 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
# refer: https://stackoverflow.com/questions/18172257/efficient-calculation-of-fibonacci-series/23462371#23462371 | |
import functools | |
@functools.lru_cache(None) | |
def fib(n): | |
if n < 2: | |
return n | |
return fib(n-1) + fib(n-2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment