Programmers / 피보나치 수

Programmers / 피보나치 수

Problem

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;
        }
    }
}
Solution 1
  • Description
  • Time Complexity
  • Space Complexity