标签:png 规划 info class lang 动态规划 end 越界 solution
Python
class Solution(object):
def fib(self, n):
"""
:type n: int
:rtype: int
"""
# 递归 20/51 超时
# if n == 0:
# return 0
# if n == 1:
# return 1
# return (self.fib(n - 1) + self.fib(n - 2)) % 1000000007
# 动态规划
# dp = []
# dp.append(0)
# dp.append(1)
# for i in range(2, n+1):
# dp.append((dp[i - 1] + dp[i - 2]) % 1000000007)
# return dp[n]
# 交替记忆n-1和n-2
n2, n1 = 0, 1
for _ in range(n):
n2, n1 = n1, n2 + n1
return n2 % 1000000007
标签:png 规划 info class lang 动态规划 end 越界 solution
原文地址:https://www.cnblogs.com/cling-cling/p/12911938.html