본문 바로가기

알고리즘 테스트 공부

덧칠하기

코드 : 

class Solution {
    public int solution(int n, int m, int[] section) {
        int answer = 0;
        
        int size = section.length; // section 크기
        int next = section[0]; // 롤러가 지나갈 다음 자리
        int idx = 0; // section idx
        
        while( idx < size ) {
            if (next <= section[idx]) {
                next = section[idx] + m;
                answer++;
            }
            idx++;
        }
        
        return answer;
    }
}

'알고리즘 테스트 공부' 카테고리의 다른 글

카드뭉치  (0) 2023.08.27
대충만든 자판  (0) 2023.08.26
바탕화면 정리  (0) 2023.08.25
조건에 부합하는 중고거래 댓글 조회하기(SQL)  (0) 2023.08.23
공원산책  (0) 2023.08.22