Playground/자바문제집

[프로그래머스] 피보나치 수

미숫가루설탕많이 2023. 4. 7. 00:01

 

 
class Solution {
    public int solution(int n) {
        int answer[] = new int[n + 1];
        answer[0] = 0;
        answer[1] = 1;
        
        for (int i = 2; i <= n; i++) {
            int fibo = answer[i - 2] + answer[i - 1];
            answer[i] = fibo % 1234567;
        }
        
        return answer[n];
    }
}