剑指 Offer 10- I. 斐波那契数列 - 力扣(LeetCode) (leetcode-cn.com)
class Solution {
public:
int fib(int n) {
if(n==0) return 0;
vector<int>res(n+1);
res[0]=0;
res[1]=1;
for(int i=2;i<n+1;i++) res[i]=(res[i-1]+res[i-2])%1000000007;
return res[n]%1000000007;
}
};