问题
思路
DP,斐波那契数列是转移方程。
代码
class Solution {
public:
int climbStairs(int n) {
if(1==n) return 1;
else if(2==n) return 2;
else{
int f1 = 1;
int f2 = 2;
for(int i = 3; i <= n; ++i){
int t = f1+f2;
f1 = f2;
f2 = t;
}
return f2;
}
}
};