Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fib数列 #28

Open
zhaochj opened this issue Apr 21, 2018 · 0 comments
Open

fib数列 #28

zhaochj opened this issue Apr 21, 2018 · 0 comments

Comments

@zhaochj
Copy link

zhaochj commented Apr 21, 2018

def fib1(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib1(n-1) + fib1(n-2)

memo = {0:0, 1:1}
def fib2(n):
if not n in memo:
memo[n] = fib2(n-1)+fib2(n-2)
return memo[n]

第二种方法似乎不会在计算上有什么优势,求大于1的fib数列都需要全部计算一次。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant