Skip to content

Commit 2217e31

Browse files
committed
climbing-stairs solution
1 parent 5655b10 commit 2217e31

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

climbing-stairs/yayyz.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
if n <= 2:
4+
return n
5+
dp = [0] * (n + 1) # n 번째의 계단을 오르는 방법을 찾기 위해 dp배열 생성
6+
dp[0] = 1
7+
dp[1] = 1
8+
# n번째의 계단을 오르기 위해서는
9+
# n-1, n-2번째의 계단에서 올수있는 경우의 수들의 합이 n번째 계단을 오르기 위한 모든 경우의 수
10+
for i in range(2, n + 1):
11+
dp[i] = dp[i-1] + dp[i-2]
12+
return dp[n]

0 commit comments

Comments
 (0)