Skip to content

Instantly share code, notes, and snippets.

@hiepph
Created March 24, 2020 15:54
Show Gist options
  • Save hiepph/652f3988a08364456e2a17d96abf93b0 to your computer and use it in GitHub Desktop.
Save hiepph/652f3988a08364456e2a17d96abf93b0 to your computer and use it in GitHub Desktop.
Fibonacci with memoization
# 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