public int solution(int[][] targets) {
Arrays.sort(targets, Comparator.comparingInt(target -> target[1]));
int lastLocation = -1;
int missileCnt = 0;
for (int[] target : targets) {
if (targetIsAfterLastLocation(target, lastLocation)) {
missileCnt++;
lastLocation = target[1];
}
}
return missileCnt;
}
private boolean targetIsAfterLastLocation(int[] target, int lastLocation) {
return target[0] >= lastLocation;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/181188