-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path253-meetingRoom.java
More file actions
39 lines (36 loc) · 1011 Bytes
/
253-meetingRoom.java
File metadata and controls
39 lines (36 loc) · 1011 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
32
33
34
35
36
37
38
39
import java.util.*;
class Node {
int start;
int time;
Node(int start, int time) {
this.start = start; // start在后
this.time = time;
}
}
class NodeComparator implements Comparator<Node> {
@Override
public int compare(Node a, Node b) {
if(a.time != b.time) return a.time-b.time;
else return a.start - b.start;
}
}
class Solution_253 {
public int minMeetingRooms(int[][] intervals) {
int n = intervals.length;
if(n<=1) return n;
Node[] node = new Node[2*n];
int index=0;
for(int i=0; i<intervals.length; i++) {
node[index++] = new Node(1, intervals[i][0]);
node[index++] = new Node(0, intervals[i][1]);
}
Arrays.sort(node, new NodeComparator());
int count=0, max=0;
for(int i=0; i<node.length; i++) {
if(node[i].start == 1) count++;
else count--;
max = Math.max(max, count);
}
return max;
}
}