代码随想录——爬楼梯(Leetcode70)
动态规划
class Solution {
public int climbStairs(int n) {
if(n == 0 || n == 1 || n == 2){
return n;
}
int[] dp = new int[n + 1];
dp[0] = 0;
dp[1] = 1;
dp[2] = 2;
for(int i = 3; i <= n; i++){
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
}
原文地址:https://blog.csdn.net/qq_46574748/article/details/140341796
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!