Problem
- Link
- Description
- 피보나치 수를 구하고 1234567로 나눈 나머지 값 반환
- Type
- 동적 프로그래밍
Solution 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
private static final int[] sumArray = new int[100000 + 1];
public int solution(int n) {
// Retrun for 0, 1
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
}
// Check sumArray and Sum
if (sumArray[n] != 0) {
return sumArray[n] % 1234567;
} else {
int sum = solution(n-1) + solution(n-2);
sumArray[n] = sum;
return sum % 1234567;
}
}
}
-
Description
-
Time Complexity
-
Space Complexity