class Solution:
# def f(self,n):
# if n==0:
# return 0
# if n==1:
# return 1
# res= self.f(n - 1) + self.f(n - 2)
# return res
def fib(self, n: int) -> int:
# return self.f(n)
dp=[None for _ in range(n+1)]
for i in range(n+1):
if i==0:
dp[i]=0
continue
if i==1:
dp[i]=1
continue
dp[i]=(dp[i-1]+dp[i-2]) % 1000000007
return dp[n]
LEETCODE 126. 斐波那契数
最新推荐文章于 2024-08-25 17:36:33 发布