We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2cfd02a + 7d316e1 commit 59406aaCopy full SHA for 59406aa
1 file changed
climbing-stairs/samthekorean.py
@@ -1,3 +1,24 @@
1
+# TC: O(n) — the loop runs n-2 times in the worst case
2
+# SC: O(1) — only a constant number of variables are used (a, b, c)
3
+class Solution:
4
+ def climbStairs(self, n: int) -> int:
5
+ if n == 1 :
6
+ return 1
7
+ if n == 2 :
8
+ return 2
9
+
10
+ a = 1
11
+ b = 2
12
13
+ for i in range(n - 2) :
14
+ c = a + b
15
+ a = b
16
+ b = c
17
18
+ return b
19
20
21
+# 이전 풀이
22
# Time complexity : O(n)
23
# Space complexity : O(1)
24
class Solution:
@@ -16,3 +37,4 @@ def climbStairs(self, n: int) -> int:
37
a, b = b, result
38
39
return result
40
0 commit comments