Skip to content

Commit 3f859c0

Browse files
committed
climbing staris solution
1 parent 2dd7074 commit 3f859c0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

climbing-stairs/devyejin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution(object):
2+
def climbStairs(self, n):
3+
"""
4+
:type n: int
5+
:rtype: int
6+
"""
7+
if n <= 2:
8+
return n
9+
10+
dp = [0] * (n + 1)
11+
dp[1], dp[2] = 1, 2
12+
13+
for i in range(3, n + 1):
14+
dp[i] = dp[i-1] + dp[i-2]
15+
16+
return dp[n]

0 commit comments

Comments
 (0)