Skip to content

Commit be85556

Browse files
committed
solved climbing stairs
:
1 parent 532c978 commit be85556

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

climbing-stairs/samthekorean.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time complexity : O(n)
2+
# Space complexity : O(n)
3+
class Solution:
4+
def climbStairs(self, n: int) -> int:
5+
a = 1
6+
b = 2
7+
result = 0
8+
if n == 1:
9+
return a
10+
11+
if n == 2:
12+
return b
13+
14+
for i in range(3, n + 1):
15+
result = a + b
16+
a, b = b, result
17+
18+
return result

0 commit comments

Comments
 (0)