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 3320013 commit 6211b14Copy full SHA for 6211b14
climbing-stairs/pmjuu.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ def climbStairs(self, n: int) -> int:
3
+ # dp[i] represents the number of distinct ways to climb to the ith step.
4
+ # Base cases:
5
+ # - There is 1 way to reach step 0 (doing nothing).
6
+ # - There is 1 way to reach step 1 (a single step).
7
+ dp = [0] * (n + 1)
8
+ dp[0], dp[1] = 1, 1
9
+
10
+ for i in range(2, n + 1):
11
+ dp[i] = dp[i - 1] + dp[i - 2]
12
13
+ return dp[n]
14
15
+# Complexity
16
+# - time: O(n)
17
+# - space: O(n)
0 commit comments