랄라

LV2 - 멀리뛰기 본문

스터디/코딩 테스트(프로그래머스)

LV2 - 멀리뛰기

devdaeun 2025. 7. 3. 18:19

https://school.programmers.co.kr/learn/courses/30/lessons/12914#qna

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr


*답변

더보기
class Solution {
    public long solution(int n) {
        long answer = 0;
        int mod = 1234567;
        long[] counter = new long[n+1];
        counter[0] = 0;
        counter[1] = 1;
        
        if(n > 1){
            counter[2] = 2;
        }
        
        for(int i=3; i<=n;i++){
            counter[i] = (counter[i-1] + counter[i-2]) %mod;
        }
        answer = counter[n];
        return answer;
    }
}