Skip to content

Commit b67d755

Browse files
author
sangbeenmoon
committed
solved climbing-stairs.
1 parent 1691de2 commit b67d755

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

climbing-stairs/sangbeenmoon.py

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

0 commit comments

Comments
 (0)