Skip to content

Commit 597919b

Browse files
committed
climbing-stairs solution
1 parent 388a7e6 commit 597919b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

climbing-stairs/hyeri0903.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
"""
4+
To find the number of distinct ways clibe to the top
5+
6+
time complexity: O(n)
7+
space complexity: O(n)
8+
"""
9+
dp = [0] * (n+1)
10+
11+
for i in range(n+1):
12+
if i == 0 or i == 1 or i == 2:
13+
dp[i] = i
14+
else:
15+
dp[i] = dp[i-1] + dp[i-2]
16+
17+
return dp[n]
18+

0 commit comments

Comments
 (0)