Last active
November 17, 2017 01:58
-
-
Save pyrofolium/2d15eeb93588281426aa7f3aac7b0285 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fib(n): | |
if n <= 1: | |
return n | |
mem = [0,1] | |
for i in xrange(2,n+1): | |
mem[(i+1)%2] = sum(mem) | |
return max(mem) | |
def fib(n): | |
if n <= 1: | |
return n | |
prev = 1 | |
prevprev = 0 | |
for i in xrange(2,n+1): | |
prev, prevprev = prevprev + prev, prev | |
return prev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment