Skip to content

Commit fbffa7e

Browse files
committed
ADD : #230 by heypaprika
1 parent 2cb3699 commit fbffa7e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

climbing-stairs/heypaprika.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
복잡도 : 예상 -> 예상한 이유
3+
4+
시간 복잡도 : O(n) -> 배열의 길이 n-2 만큼 반복하므로
5+
공간 복잡도 : O(n) -> n 길이의 배열 하나를 생성하므로
6+
"""
7+
class Solution:
8+
def climbStairs(self, n: int) -> int:
9+
if n == 1:
10+
return 1
11+
elif n == 2:
12+
return 2
13+
a = [0] * n
14+
a[0] = 1
15+
a[1] = 2
16+
for i in range(2, n):
17+
a[i] = a[i-1] + a[i-2]
18+
return a[n-1]
19+

0 commit comments

Comments
 (0)