728x90
class Solution:
def climbStairs(self, n: int) -> int:
if(n==1): return 1
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[-1]
출처: leetcode.com/problems/climbing-stairs/discuss/685099/Python-Detailed-Explanation-DP-solution
728x90
'Leetcode' 카테고리의 다른 글
303. Range Sum Query - Immutable (0) | 2020.08.16 |
---|---|
53. Maximum Subarray (0) | 2020.08.16 |
392. Is Subsequence (0) | 2020.08.15 |
121. Best Time to Buy and Sell Stock (0) | 2020.08.10 |
1025. Divisor Game (0) | 2020.08.10 |
댓글