File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ ๏ปฟ #ํด์
2+ #ํผ๋ณด๋์น ์์ด์ ์ด์ฉํ์ฌ ํน์ ๋ฒ์๋ง๋ค 1๊ณผ 2๋ฅผ ํ์ฉํ ๋ฐฉ๋ฒ์ ์๋ฅผ ๊ณ์ฐํ๋ค.
3+ #a=1, a=2 ๋ก ์ด๊ธฐ ์
ํ
ํ ๋ฐ๋ณต๋ฌธ๋ง๋ค a์ b๋ฅผ ์
๋ฐ์ดํธ ํ๋ค.
4+ # a๋ ํ์ฌ ๊ณ๋จ์ ๊ฒฝ์ฐ์ ์, b๋ ๋ค์ ๊ณ๋จ์ ๊ฒฝ์ฐ์ ์๋ก ์ค์ ํ๋ค.
5+ # ๋ฐ๋ณต๋ฌธ์ ๊ฒฐ๊ณผ๋ก n๋ฒ์งธ ๊ณ๋จ์ ์ค๋ฅด๋ ๋ฐฉ๋ฒ์ ์(a)๋ฅผ ๋ฐํํ๋ค.
6+
7+
8+ #Big O
9+ #N: ๋งค๊ฐ๋ณ์ n์ ํฌ๊ธฐ(๊ณ๋จ ๊ฐฏ์)
10+
11+ #Time Complexity: O(N)
12+ #- for loop ๋ n-1๋ฒ : O(N)
13+
14+ #Space Complexity: O(1)
15+ #- ์์ a,b๋ง ์ฌ์ฉ : O(1)
16+
17+ class Solution (object ):
18+ def climbStairs (self , n ):
19+ """
20+ :type n: int
21+ :rtype: int
22+ """
23+ a ,b = 1 ,2 #F(0) = 1, F(1) =2
24+ for i in range (1 ,n ):
25+ a ,b = b , a + b #Update a and b each iteration
26+ #Fn = Fn-1 + Fn-2
27+
28+ return a
29+
You canโt perform that action at this time.
0 commit comments