1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public int minmumNumberOfHost (int n, int[][] startEnd) {
Arrays.sort(startEnd,(a,b)->{
if(a[0]==b[0]){
return Integer.compare(a[1], b[1]);
}
return Integer.compare(a[0], b[0]);
});
PriorityQueue<Integer> queue = new PriorityQueue<>();
int maxHost = 0;
for(int[] activity:startEnd){
while(!queue.isEmpty()&&queue.peek()<=activity[0]){
queue.poll();
}
queue.offer(activity[1]);
maxHost = Math.max(maxHost,queue.size());
}
return maxHost;
}
|