-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
70.py
25 lines (22 loc) · 829 Bytes
/
70.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
__________________________________________________________________________________________________
sample 16 ms submission
class Solution:
def climbStairs(self, n: int) -> int:
if n < 3:
return n
cur, prev = 2, 1
for i in range(2, n):
cur = cur + prev
prev = cur - prev
return cur
__________________________________________________________________________________________________
sample 12824 kb submission
class Solution:
def climbStairs(self, n: int) -> int:
if n <= 2:
return n
dp = [1, 2] + [0]*(n-2)
for i in range(2, n):
dp[i] = dp[i-1] + dp[i-2]
return dp[-1]
__________________________________________________________________________________________________