public int solution(int[][] routes) {
Arrays.sort(routes, Comparator.comparingInt(o -> o[1]));
int cameraLocation = routes[0][1];
int cameraCount = 1;
for (int[] route : routes) {
if (route[0] > cameraLocation) {
cameraCount++;
cameraLocation = route[1];
}
}
return cameraCount;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/42884