@@ -7,26 +7,26 @@ function climbStairs(n: number): number {
77 * 1 -> [1]
88 * 2 -> [1,1] [2]
99 * 3 -> [1,1,1] [2,1] [1,2]
10- * 4 -> [1,1,1,1] [2,1,1] [1,2,1] [1,1,2] [2,2]
10+ * 4 -> [1,1,1,1] [2,1,1] [1,2,1] [1,1,2] [2,2]
1111 * 5 -> [1,1,1,1,1] [2,1,1,1] [1,2,1,1] [1,1,2,1] [1,1,1,2] [2,2,1], [1,2,2], [2,1,2]
12- * 6 -> [1,1,1,1,1,1] [2,1,1,1,1] [...] [1,1,1,1,2] [2,2,1,1], [2,1,2,1], [2,1,1,2] [1,1,2,2], [1,2,1,2], [1,2,2,1]
13- => (1- n, 2- 0) n가지 (1:n-2, 2:1) (n-1)*(n-2)/(n-2) 가지 (1: n-4, 2: n/2) (n-2)*(n-3)/2 가지
12+ * 6 -> [1,1,1,1,1,1] [2,1,1,1,1] [...] [1,1,1,1,2] [2,2,1,1], [2,1,2,1], [2,1,1,2] [1,1,2,2], [1,2,1,2], [1,2,2,1]
13+ => (1: n, 2: 0) n가지 (1:n-2, 2:1) / n가지 (1: n-4, 2: n/2) C(n, n/2) 가지
1414 */
1515
16- // # solution 1
17- // TC: O(N)
18- // SC: O(N)
16+ // # Solution 1
17+
1918 // const stair = {1: 1, 2:2}
2019 // for(let i = 3; i<=n; i++){
2120 // stair[i] = stair[i-1] + stair[i-2]
2221 // }
23-
24- // # solution 2
2522 // TC: O(N)
26- // SC: O(1)
23+ // SC: O(N)
24+
25+ // # Solution 2
26+
2727 // if(n < 3) return n
28- // let curr = 2
29- // let prev = 1
28+ // let curr = 2 // 현재 계단을 오르는 방법 수
29+ // let prev = 1 // 이전 계단을 오르는 방법 수
3030
3131 // for(let i=0; i<n-2; i++){
3232 // const next = prev + curr;
@@ -35,10 +35,10 @@ function climbStairs(n: number): number {
3535 // }
3636
3737 // return curr
38+ // TC: O(N)
39+ // SC: O(1)
3840
3941 // # Solution 3: 재귀
40- // TC: O(N)
41- // SC: O(N)
4242 const memo = { 1 : 1 , 2 : 2 } ;
4343 function calculateClimbingWay ( n , memo ) {
4444 if ( ! ( n in memo ) ) {
@@ -51,4 +51,6 @@ function climbStairs(n: number): number {
5151 return memo [ n ] ;
5252 }
5353 return calculateClimbingWay ( n , memo ) ;
54+ // TC: O(N)
55+ // SC: O(N)
5456}
0 commit comments