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 d2445db commit 6f514c5Copy full SHA for 6f514c5
70.climbing_stairs/stairs.py
@@ -33,18 +33,30 @@
33
from typing import List
34
35
class Solution:
36
- def climbStairs(self, n: int) -> int:
+ def climbStairs(self, n: int) -> int:
37
if n < 2:
38
return n
39
-
40
- dp = [0, 1]
+ one, two = 0, 1
41
i = 2
42
while i <= n+1:
43
- tmp = dp[1]
44
- dp[1] = dp[0] + dp[1]
45
- dp[0] = tmp
+ tmp = two
+ two = one+two
+ one = tmp
46
i+=1
47
- return dp[1]
+ return two
+
48
+ # def climbStairs(self, n: int) -> int:
49
+ # if n < 2:
50
+ # return n
51
52
+ # dp = [0, 1]
53
+ # i = 2
54
+ # while i <= n+1:
55
+ # tmp = dp[1]
56
+ # dp[1] = dp[0] + dp[1]
57
+ # dp[0] = tmp
58
+ # i+=1
59
+ # return dp[1]
60
61
# time and space O(n)
62
# def climbStairs(self, n: int) -> int:
0 commit comments