LeetCode 70_ 爬楼梯
1. 题目描述
注: 动态规划
2. 代码
1 class Solution: 2 def climbStairs(self, n: int) -> int: 3 if n <= 2: 4 return n 5 else: 6 dp = [0] * (n+1) 7 dp[1] = 1 8 dp[2] = 2 9 for i in range(3,n+1): 10 dp[i] = dp[i-1] + dp[i-2] 11 return dp[n]
思路: