231222 요격 시스템

Jongleee·2023년 12월 22일
0

TIL

목록 보기
449/737
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

0개의 댓글