没啥好说的,递归和动态规划的入门。
开始刷动态规划了。
class Solution {
public:
int Fibonacci(int n) {
int fir = 0, sec = 1, res = 1;
for (int i = 2; i <= n; ++i) {
res = fir + sec;
fir = sec;
sec = res;
}
return res;
}
};