[프로그래머스] Lv.1 덧칠하기.java

hgghfgf·2023년 6월 23일
0

프로그래머스

목록 보기
199/227

덧칠하기.java

class Solution {
    public int solution(int n, int m, int[] section) {
        int answer = 0;
        int size = section.length;
        int next = section[0];
        int idx = 0;
        
        while(idx<size){
            if(next <= section[idx]){
                next = section[idx] + m;
                answer++;
            }
            idx++;
        }
        
        return answer;
    }
}

출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/161989

0개의 댓글