forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDH_42884.java
More file actions
31 lines (27 loc) · 686 Bytes
/
DH_42884.java
File metadata and controls
31 lines (27 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
/*
* 단속 카메라
*/
public class DH_42884 {
static int solution(int[][] routes) {
PriorityQueue<int[]> q = new PriorityQueue<int[]>((o1, o2) -> {
if(o1[0] == o2[0]) return Integer.compare(o1[1], o2[1]);
return Integer.compare(o1[0], o2[0]);
});
for(int[] route: routes) q.add(route);
int answer = 0;
int camera = Integer.MIN_VALUE;
while(!q.isEmpty()) {
int[] current = q.poll();
if(camera < current[0]) {
camera = current[1];
answer += 1;
}
}
return answer;
}
public static void main(String[] args) {
int[][] routes = {{-20,-15}, {-14,-5}, {-18,-13}, {-5,-3}};
System.out.println(solution(routes));
}
}