70. Climbing Stairs

Posted johnnyzhao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了70. Climbing Stairs相关的知识,希望对你有一定的参考价值。

package LeetCode_70

/**
 * 70. Climbing Stairs
 * https://leetcode.com/problems/climbing-stairs/description/
 * */
class Solution {
    fun climbStairs(n: Int): Int {
        if (n <= 2) {
            return n
        }
        //method 1: TLE
        //return climbStairs(n-1)+climbStairs(n-2)
        //dp
        val dp = IntArray(n)
        dp[0] = 1
        dp[1] = 2
        for (i in 2 until n) {
            dp[i] = dp[i - 2] + dp[i - 1]
        }
        return dp[dp.size - 1]
    }
}

 

以上是关于70. Climbing Stairs的主要内容,如果未能解决你的问题,请参考以下文章

70. Climbing Stairs

70. Climbing Stairs

70. Climbing Stairs

LeetCode 70. Climbing Stairs

#LeetCode# 70. Climbing Stairs

70. Climbing Stairs