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 4ba78fc commit 081c9ddCopy full SHA for 081c9dd
climbing-stairs/ayosecu.py
@@ -0,0 +1,36 @@
1
+class Solution:
2
+ """
3
+ - Time Complexity: O(n)
4
+ - Space Complexity: O(n)
5
6
+ def climbStairs(self, n: int) -> int:
7
8
+ - DP Formation
9
+ - dp[0] = 1
10
+ - dp[1] = 1
11
+ - dp[2] = dp[1] + dp[0] = 2
12
+ - dp[3] = dp[2] + dp[1] = 3
13
+ - dp[i] = dp[i - 1] + dp[i - 2]
14
15
+ if n <= 1:
16
+ return 1
17
+
18
+ dp = [1] * (n + 1)
19
20
+ for i in range(2, n + 1):
21
+ dp[i] = dp[i - 1] + dp[i - 2]
22
23
+ return dp[-1]
24
25
26
+tc = [
27
+ (1, 1),
28
+ (2, 2),
29
+ (3, 3),
30
+ (4, 5)
31
+]
32
33
+for i, (n, e) in enumerate(tc, 1):
34
+ sol = Solution()
35
+ r = sol.climbStairs(n)
36
+ print(f"TC {i} is Passed!" if r == e else f"TC {i} is Failed! - Expected: {e}, Result: {r}")
0 commit comments