We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 9a6fe58 + 589e242 commit 21bf40bCopy full SHA for 21bf40b
1 file changed
lkhyun/202512/12 PGM Lv2 피보나치 수.md
@@ -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
23
24
+}
25
+```
0 commit comments