LeetCode(力扣)70. 爬楼梯Python

LeetCode70. 爬楼梯

题目链接

https://leetcode.cn/problems/climbing-stairs/
在这里插入图片描述

代码

class Solution:
    def climbStairs(self, n: int) -> int:
        if n <= 1:
            return n
        dp = [0] * (n + 1)
        dp[1] = 1
        dp[2] = 2
        for i in range(3, n + 1):
            dp[i] = dp[i - 1] + dp[i - 2]
        return dp[n]

猜你喜欢

转载自blog.csdn.net/qq_44953660/article/details/132998293