File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * ์๊ฐ ๋ณต์ก๋: O(n)
3+ * - n = 5 ๊ฒฝ์ฐ๋ฅผ ๊ฐ์ ํ๊ณ ์๊ฐํด๋ณด๊ธฐ
4+ * - 3์ธต ๊ณ๋จ -> 2์ธต, 1์ธต ๊ณ์ฐ (์ด ๊ฒฝ์ฐ๋ ์ด๋ฏธ ๋ฉ๋ชจ๋์ด ์์ด์ ๋ณ๋๋ก ๊ณ์ฐํ์ง ์์)
5+ * - 4์ธต ๊ณ๋จ -> 3์ธต, 2์ธต ๊ณ์ฐ (2์ธต์ ๋ฉ๋ชจ์ ์๋ ๊ฒ ํ์ฉ)
6+ * - 5์ธต ๊ณ๋จ -> 4์ธต, 3์ธต ๊ณ์ฐ (3์ธต์ ๋ฉ๋ชจ์ ์๋ ๊ฒ ํ์ฉ)
7+ * - ...
8+ * - ๊ฐ ๋จ๊ณ ๋ณ๋ก (๋ฉ๋ชจ๋ฅผ ํ์ฉํด) ์์ง ๊ณ์ฐ๋์ง ์์ ๊ฒ์ ํ ๋ฒ์ฉ ํธ์ถํ๊ฒ ๋๋ฏ๋ก O(n)
9+ * - ๊ทผ๋ฐ ๋ง์ฝ ๋ฉ๋ชจ๋ฅผ ์ฌ์ฉํ์ง ์์ผ๋ฉด? (์ค๋ณต ํธ์ถ์ด ๋ง์ด ์ผ์ด๋จ ... O(n^2))
10+ *
11+ * ๊ณต๊ฐ ๋ณต์ก๋: O(n)
12+ */
13+ class Solution {
14+ public int climbStairs (int n ) {
15+ int [] memo = new int [n + 1 ];
16+ return climbStairs (n , memo );
17+ }
18+
19+ public int climbStairs (int n , int [] memo ) {
20+ if (n == 1 ) return 1 ;
21+ if (n == 2 ) return 2 ;
22+
23+ if (memo [n ] > 0 ) return memo [n ];
24+
25+ memo [n ] = climbStairs (n - 1 , memo ) + climbStairs (n - 2 , memo );
26+ return memo [n ];
27+ }
28+ }
You canโt perform that action at this time.
0 commit comments