Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 655f25f

Browse files
이지영: [PG] 181188 요격 시스템_241115
1 parent 82008e2 commit 655f25f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎Programmers/Level2/JY_181188.java‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int solution(int[][] targets) {
5+
int answer = 0;
6+
7+
// 시작점 기준으로 정렬
8+
Arrays.sort(targets, (o1, o2)->o1[0]-o2[0]);
9+
10+
int N = targets.length;
11+
int bound = 0; // 경계값
12+
for(int i=0; i<N; i++) {
13+
int s = targets[i][0];
14+
int e = targets[i][1];
15+
16+
// 새로운 요격 발사해야 함
17+
if(s >= bound) {
18+
answer++;
19+
bound = e;
20+
} else {
21+
bound = Math.min(bound, e); // 현재 요격으로 가능한 모든 범위의 미사일을 없애야 하므로 범위가 가장 작은 미사일로 저장
22+
}
23+
}
24+
25+
return answer;
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /