70. Climbing Stairs

链接地址: https://leetcode.com/problems/climbing-stairs/description/
解题思路:

  1. 发现其满足动态规划标准
  2. 每一个台阶都是前两个台阶的数量相加

代码:

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];
}

}

你可能感兴趣的:(70. Climbing Stairs)