https://school.programmers.co.kr/learn/courses/30/lessons/161989
마지막으로 롤러가 칠해진 포지션만 두면 쉽게 풀 수 있는 문제다.
Section 배열 모두 순회하면서 안 칠해진 포인트를 찾았다면
그걸 시작점으로 잡고 롤러 길이만큼 갱신하면 된다.
오름차순 기준이라 했으니 이 방법이 section[n]
번째를 포함해서 오른쪽까지 가장 넓게 칠할 수 있는 방법이 되기 때문
class Solution {
public int solution(int n, int m, int[] section) {
int answer = 0;
int end = 0;
for (int s : section) {
if (s > end) {
answer++;
end = s + m - 1;
}
}
return answer;
}
}