Skip to content

Commit 21bf40b

Browse files
authored
Merge pull request #1655 from AlgorithmWithGod/lkhyun
[20251212] PGM / Lv2 / 피보나치 수 / 이강현
2 parents 9a6fe58 + 589e242 commit 21bf40b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
```java
2+
class Solution {
3+
private static final int MOD = 1234567;
4+
private int[] memo;
5+
6+
public int solution(int n) {
7+
memo = new int[n + 1];
8+
return fib(n);
9+
}
10+
11+
private int fib(int n) {
12+
if (n == 0) return 0;
13+
if (n == 1) return 1;
14+
15+
// 이미 계산된 값이 있으면 반환
16+
if (memo[n] != 0) {
17+
return memo[n];
18+
}
19+
20+
// 계산 후 메모에 저장
21+
memo[n] = (fib(n - 1) + fib(n - 2)) % MOD;
22+
return memo[n];
23+
}
24+
}
25+
```

0 commit comments

Comments
 (0)