Skip to content

Commit 7c787b2

Browse files
committed
[Week05] PGS: 요격 시스템
1 parent 85fce18 commit 7c787b2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package week06.PGS_요격시스템;
2+
3+
import java.util.*;
4+
class Solution {
5+
public int solution(int[][] targets) {
6+
int answer = 0;
7+
Arrays.sort(targets, (o1, o2) -> o1[0] - o2[0]);
8+
9+
int start = -1; //현재 요격 미사일의 범위
10+
int end = 100_000_001;
11+
for (int i = 0; i < targets.length; i++) {
12+
if (targets[i][0] >= end) {
13+
answer++;
14+
start = -1;
15+
end = 100_000_001;
16+
}
17+
start = Math.max(start, targets[i][0]);
18+
end = Math.min(end, targets[i][1]);
19+
}
20+
21+
answer++;
22+
return answer;
23+
}
24+
}

0 commit comments

Comments
 (0)