https://leetcode.com/problems/climbing-stairs/
Climbing Stairs - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
DP의 또다른 대표 문제인 계단 문제입니다.
이 기본 유형에서는 피보나치와 코드가 거의 같다고 보셔도 될 것 같습니다.
계단을 오르는 갯수, 지뢰, 내려가기 등을 섞어 여러 유형으로 활용되는 문제입니다.
class Solution:
def climbStairs(self, n: int) -> int:
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
for i in range(2,n+1):
dp[i] = dp[i-2] + dp[i-1]
return dp[n]
for i in range(1,46):
print(Solution().climbStairs(i))
728x90
'🔍 알고리즘 > Leetcode' 카테고리의 다른 글
[Python] Leetcode 21. Merge Two Sorted Lists (Easy) (0) | 2022.07.23 |
---|---|
[Python] Leetcode 746. Min Cost Climbing Stairs (Easy) (0) | 2022.07.22 |
[Python] Leetcode 1137. N-th Tribonacci Number(Easy) (0) | 2022.07.22 |
[Python] Leetcode 509. Fibonacci Number (Easy) (0) | 2022.07.22 |
[Python] Leetcode 392. Is Subsequence (Easy) (0) | 2022.07.22 |