Skip to content

Commit c3a296d

Browse files
committed
feat: week2 - climbing stairs
1 parent bf7f794 commit c3a296d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

β€Žclimbing-stairs/Seoya0512.pyβ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'''
2+
Approach: Dynamic Programming
3+
- ν˜Όμžμ„œ ν•΄κ²°ν•˜λ €κ³  고민을 30λΆ„ 이상 ν–ˆμœΌλ‚˜ μ‹€νŒ¨ν•΄μ„œ μ•Œκ³ λ‹¬λ ˆ μ„ μƒλ‹˜μ˜ λΈ”λ‘œκ·Έ 도움을 λ°›μ•˜μŠ΅λ‹ˆλ‹€.
4+
- ν•΄λ‹Ή 문제λ₯Ό 톡해 동적 κ³„νš,Dynamic Programming
5+
- 더 적은 μž…λ ₯에 λŒ€ν•œ 닡을 λ¨Όμ € κ΅¬ν•΄μ„œ μ €μž₯해놓고, 더 큰 μž…λ ₯에 λŒ€ν•œ 닡을 ꡬ할 λ•Œ ν™œμš©ν•˜λŠ” 방식에 λŒ€ν•΄ ν•™μŠ΅ν•  수 μžˆμ—ˆμŠ΅λ‹ˆλ‹€!
6+
7+
Time Complexity: O(n)
8+
- for loop이 n번 μˆœνšŒν•˜λ©° 각 값에 λŒ€ν•œ μ—°μ‚° O(n) λ°œμƒ
9+
Space Complexity: O(n)
10+
- nums λ”•μ…”λ„ˆλ¦¬μ— 각 계단 μˆ˜μ— λŒ€ν•œ 경우의 수λ₯Ό μ €μž₯
11+
'''
12+
class Solution:
13+
def climbStairs(self, n: int) -> int:
14+
nums = {1:1, 2:2}
15+
for i in range(3, n+1):
16+
nums[i] = nums[i-1] + nums[i-2]
17+
return nums[n]

0 commit comments

Comments
Β (0)