We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1e8d5cf commit 2415f2dCopy full SHA for 2415f2d
โclimbing-stairs/sungjinwi.pyโ
@@ -0,0 +1,21 @@
1
+'''
2
+ - ๋ฌ๋ ์คํฐ๋ ํ์ด ์ฐธ๊ณ ํจ
3
+ ํ์ด :
4
+ n๋ฒ์งธ ๊ณ๋จ์ ์ค๋ฅด๊ธฐ ์ํด์๋ n-1 ๋๋ n-2์ ์๋ค๊ฐ ์ฌ๋ผ์ค๋ ์ ๋ฐ์ ์์ผ๋ฏ๋ก f(n-1) + f(n-2)์ ๊ฐ
5
+ dp ๋ฐฐ์ด๋ก ํ ์๋ ์์ง๋ง ๋ ๊ฐ์ ๋ณ์์ ์ ๋ฐ์ดํธ ํ๋ ์์ผ๋ก ํ์ด
6
+
7
+ TC :
8
+ for๋ฌธ์ผ๋ก ์ธํด O(N)
9
10
+ SC :
11
+ O(1)
12
13
14
+class Solution:
15
+ def climbStairs(self, n: int) -> int:
16
+ if n < 3 :
17
+ return (n)
18
+ prv, cur = 1, 2
19
+ for _ in range(3, n + 1) :
20
+ prv, cur = cur, prv + cur
21
+ return (cur)
0 commit comments