70. Climbing Stairs
2018-07-20 本文已影响0人
becauseyou_90cd
链接地址: https://leetcode.com/problems/climbing-stairs/description/
解题思路:
- 发现其满足动态规划标准
- 每一个台阶都是前两个台阶的数量相加
代码:
class Solution {
public int climbStairs(int n) {
if(n <= 1) return 1;
int[] dp = new int[n + 1];
dp[0] = 1;
dp[1] = 1;
for(int i = 2; i <= n; i++){
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
}