剑指OFFER----面试题10-I. 斐波那契数列
链接:https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/
代码:
class Solution {
public:
int fib(int n) {
std::vector<int> vec = {0, 1};
for(int i = 2; i <= n; i++){
vec.push_back((vec[i-2] + vec[i-1])%1000000007);
}
return vec[n];
}
};