class Solution {
public int climbStairs(int n) {
if(n <= 2) return n;
int[] dp = new int[3];
dp[1] = 1;
dp[2] = 2;
int sum = 0;
for(int i = 3;i <= n;i++){
sum = dp[1] + dp[2];
dp[1] = dp[2];
dp[2] = sum;
}
return sum;
}
}
代码随想录——70. 爬楼梯
最新推荐文章于 2024-08-29 16:37:54 发布