class Solution {
public:
int climbStairs(int n) {
vector<int> dp(n+1);
dp[0] = 1;
dp[1] = 1;
for(int i = 2; i < n+1; i++){
int a = (i - 1 >= 0) ? dp[i - 1] : 0;
int b = (i - 2 >= 0) ? dp[i - 2] : 0;
dp[i] = a + b;
}
return dp[n];
}
};
网友评论