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.
1 parent 9aa35f8 commit 6fe30d9Copy full SHA for 6fe30d9
1 file changed
climbing-stairs/jylee2033.py
@@ -0,0 +1,20 @@
1
+class Solution:
2
+ def climbStairs(self, n: int) -> int:
3
+ # ways(n) = ways(n-1) + ways(n-2)
4
+
5
+ if n == 1:
6
+ return 1
7
+ elif n == 2:
8
+ return 2
9
10
+ ways = [0] * (n + 1)
11
+ ways[1] = 1
12
+ ways[2] = 2
13
14
+ for i in range(3, n + 1):
15
+ ways[i] = ways[i - 1] + ways[i - 2]
16
17
+ return ways[n]
18
19
+# Time Complexity: O(n)
20
+# Space Complexity: O(n)
0 commit comments