Created
December 28, 2017 14:20
-
-
Save faraazahmad/fb06f8d8d8d6b5290325130afb15b246 to your computer and use it in GitHub Desktop.
an optimised fibonacci generating algorithm using memoisation
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
def better_fib(n): | |
if n >= 0 and n <= 1: | |
return n | |
else: | |
fib = [0, 1] | |
for i in range(2, n + 1): | |
fib.append(fib[i - 1] + fib[i - 2]) | |
return fib[n] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment