File tree Expand file tree Collapse file tree 2 files changed +17
-14
lines changed
Expand file tree Collapse file tree 2 files changed +17
-14
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 95.7 MB, 시간: 2.87 ms
7+ 메모리: 91.9 MB, 시간: 16.42 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 06월 02일 21:37:34
19+ 2025년 06월 02일 21:43:39
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11class Solution {
2- static int DP [] ;
3-
2+ static int [] memo ;
3+
44 public int solution (int n ) {
5- DP = new int [n +1 ];
6- DP [0 ] = 0 ;
7- DP [1 ] = 1 ;
8-
9- for (int i =2 ; i <=n ; i ++){
10- DP [i ] = (DP [i -1 ] + DP [i -2 ]) % 1234567 ;
11- }
12- // return DP[n] % 1234567;
13- return DP [n ];
5+ memo = new int [n +1 ];
6+ return fib (n );
147 }
15- }
8+
9+ private int fib (int n ) {
10+ if (n == 0 ) return 0 ;
11+ if (n == 1 ) return 1 ;
12+ if (memo [n ] != 0 ) return memo [n ]; // 이미 계산된 값이면 바로 반환
13+
14+ // 계산 후 저장(메모이제이션)
15+ memo [n ] = (fib (n -1 ) + fib (n -2 )) % 1234567 ;
16+ return memo [n ];
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments