这个题目是动态规划,简单
class Solution {
public:
int climbStairs(int n) {
int a = 0, b = 0, c = 1;
for (int i = 1; i <= n; ++i) {
a = b; //动态规划
b = c;
c = a + b;
}
return c;
}
};
这个题目是动态规划,简单
class Solution {
public:
int climbStairs(int n) {
int a = 0, b = 0, c = 1;
for (int i = 1; i <= n; ++i) {
a = b; //动态规划
b = c;
c = a + b;
}
return c;
}
};