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 b9fedda commit b9449deCopy full SHA for b9449de
1 file changed
climbing-stairs/njngwn.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ # dynamic programming with bottom-up
3
+ # Time Complexity: O(n)
4
+ # Space Complexity: O(1)
5
+ def climbStairs(self, n: int) -> int:
6
+ if n <= 2: return n
7
+ prev1, prev2 = 2, 1
8
+
9
+ for i in range(3, n+1):
10
+ prev1, prev2 = prev2 + prev1, prev1
11
12
+ return prev1
0 commit comments