We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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数列都需要全部计算一次。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
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数列都需要全部计算一次。
The text was updated successfully, but these errors were encountered: