Skip to content

Commit 3d7d49b

Browse files
committed
feat: optimize climbing-stairs
1 parent 6211b14 commit 3d7d49b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

climbing-stairs/pmjuu.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ def climbStairs(self, n: int) -> int:
1515
# Complexity
1616
# - time: O(n)
1717
# - space: O(n)
18+
19+
class Solution:
20+
def climbStairs(self, n: int) -> int:
21+
prev, curr = 1, 1
22+
23+
for _ in range(2, n + 1):
24+
prev, curr = curr, prev + curr
25+
26+
return curr
27+
28+
# Complexity
29+
# - time: O(n)
30+
# - space: O(1)

0 commit comments

Comments
 (0)