프로그래머스 연습문제 덧칠하기 [JAVA] - 23년 3월 25일

Denia·2023년 3월 25일
0

코딩테스트 준비

목록 보기
172/201
class Solution {
    public int solution(int totalSectionNum, int rollerLength, int[] sectionsToPaint) {
        int answer = 0;

        int firstSection = sectionsToPaint[0];
        int paintRollerLength = firstSection + rollerLength - 1;
        answer++;

        for (int idx = 1; idx < sectionsToPaint.length; idx++) {
            int nextSection = sectionsToPaint[idx];

            if (nextSection > paintRollerLength) {
                paintRollerLength = nextSection + rollerLength - 1;
                answer++;
            }
        }

        return answer;
    }
}

profile
HW -> FW -> Web

0개의 댓글