-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLC253.java
More file actions
41 lines (31 loc) · 804 Bytes
/
LC253.java
File metadata and controls
41 lines (31 loc) · 804 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
40
253. Meetings Room II
Given an array meeting time intervals containing start and end time [[s1, e1], [s2,e2], ... ] (s1 < e1),
find the minimum number of conference room required.
Example 1:
Input:
Input = [[0,30],[5,10],[15,20]]
Output: 2
Example 2:
Input:
Input = [[7,10],[2,4]]
Output: 1
*/
class Solution
{
public int minimumMeetingRooms(Interval[] intervals)
{
if (intervals == null || intervals.length == 0)
return 0;
Arrays.sort(intervals, (t1, t2) -> (t1.start - t2.start));
PriorityQueue<Integer> minHeap = new PriorityQueue<>();
for (Interval i : intervals)
{
if (minHeap.size() > 0 && minHeap.peek() <= i.start)
{
minHeap.poll();
}
minHeap.offer(i.end);
}
return minHeap.size();
}
}