File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ // 공간 복잡도를 줄인 2번째 버전
2
+ class Solution {
3
+ public int climbStairs (int n ) {
4
+ int back = 1 ;
5
+ int front = 2 ;
6
+ int target = 0 ;
7
+
8
+ if (n == 1 ) return back ;
9
+ if (n == 2 ) return front ;
10
+
11
+ for (int i = 1 ; i < n -1 ; i ++){
12
+ target = front + back ;
13
+ back = front ;
14
+ front = target ;
15
+ }
16
+
17
+ return target ;
18
+ }
19
+ }
20
+
21
+
22
+ // 초기 버전
1
23
class Solution {
2
24
public int climbStairs (int n ) {
3
25
int [] stairs = new int [n +1 ];
@@ -12,3 +34,8 @@ public int climbStairs(int n) {
12
34
}
13
35
}
14
36
37
+ // 1 : 1
38
+ // 2 : [1] + 1, 2 1+1 2 2개
39
+ // 3 : [2-1] + 1, [2-2] + 1, [1] + 2 1+1+1 2+1 1+2 3개
40
+ // 4 : [3-1] + 1, [3-2] + 1, [3-3] + 1 1+1+1+1 2+1+1 1+2+1 1+1+2 2+2 5개
41
+ // 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 2+1+2 1+2+2 8개
You can’t perform that action at this time.
0 commit comments