Skip to content

Commit

Permalink
feat: climbing-stairs 공간 복잡도 최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaedie committed Dec 22, 2024
1 parent 72aaa3a commit 6ba9c38
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions climbing-stairs/Chaedie.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ def climbStairs(self, n: int) -> int:
for i in range(3, n+1):
dp.append(dp[i-1] + dp[i-2])
return dp[n]

'''
solution2:
위 솔루션에서 공간 복잡도 최적화
time O(n)
space O(1)
'''
class Solution:
def climbStairs(self, n: int) -> int:
pt1, pt2 = 1,1
for i in range(2, n+1):
temp = pt2
pt2 = pt1 + pt2
pt1 = temp
return pt2

0 comments on commit 6ba9c38

Please sign in to comment.