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 388a7e6 commit 597919bCopy full SHA for 597919b
1 file changed
climbing-stairs/hyeri0903.py
@@ -0,0 +1,18 @@
1
+class Solution:
2
+ def climbStairs(self, n: int) -> int:
3
+ """
4
+ To find the number of distinct ways clibe to the top
5
+
6
+ time complexity: O(n)
7
+ space complexity: O(n)
8
9
+ dp = [0] * (n+1)
10
11
+ for i in range(n+1):
12
+ if i == 0 or i == 1 or i == 2:
13
+ dp[i] = i
14
+ else:
15
+ dp[i] = dp[i-1] + dp[i-2]
16
17
+ return dp[n]
18
0 commit comments