File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ 1. ๋ฌธ์ ์ดํด
3+ N์ด ์ฃผ์ด์ง๋ฉด 1๋ถํฐ N๊น์ง์ ์ซ์๋ฅผ ์ด์ฉํด์ N๊น์ง ๋๋ฌ ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ ์(+1,+2๋ง ๊ฐ๋ฅ)๋ฅผ ๋ฐํํด์ผ ํ๋ ๋ฌธ์ ์. ์ค๋ณต์ ํ์ฉํ๋ ์์ด์ ์ฐพ๋ ๋ฌธ์ ์ด๋ค.
4+
5+ 2. naive algorithm ๋์ถ
6+ ํผ๋ณด๋์น ์์ด์.
7+ N=1์ผ๋ ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ ์๋ 1
8+ N=2์ผ๋ ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ ์๋ 2
9+ N=3์ผ๋ ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ ์๋ 3 (n-2๋ฒ์งธ์ n-1๋ฒ์งธ์ ํฉ)
10+
11+ 3. ์๊ฐ๋ณต์ก๋ ๋ถ์
12+
13+ O(N)
14+ 4. ์ฝ๋์์ฑ
15+ */
16+ class sangyyypark {
17+ public int climbStairs (int n ) {
18+ if (n ==1 ) return 1 ;
19+ if (n ==2 ) return 2 ;
20+ int [] dp = new int [n +1 ];
21+ dp [0 ] = 0 ;
22+ dp [1 ] = 1 ;
23+ dp [2 ] = 2 ;
24+ for (int i = 3 ; i <= n ; i ++) {
25+ dp [i ] = dp [i -2 ] + dp [i -1 ];
26+ }
27+ return dp [n ];
28+ }
29+ }
30+
You canโt perform that action at this time.
0 commit comments