230415 요격 시스템

Jongleee·2023년 4월 15일
0

TIL

목록 보기
234/576
public int solution(int[][] targets) {
    Arrays.sort(targets, (o1, o2) -> {
        return o1[1] - o2[1];
    });
    int lastLocation = -1;
    int missileCnt = 0;
    for (int[] t : targets) {
        if (t[0] >= lastLocation) {
            missileCnt++;
            lastLocation = t[1];
        }
    }
    return missileCnt;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/181188

0개의 댓글