Medium
/**
* Definition for an interval.
* public class Interval {
* int start;
* int end;
* Interval() { start = 0; end = 0; }
* Interval(int s, int e) { start = s; end = e; }
* }
*/
class Solution {
public int minMeetingRooms(Interval[] intervals) {
if (intervals == null || intervals.length == 0){
return 0;
}
Arrays.sort(intervals, new Comparator<Interval>(){
public int compare(Interval a, Interval b){
return a.start - b.start;
}
});
PriorityQueue<Interval> minHeap = new PriorityQueue<Interval>(intervals.length, new Comparator<Interval>(){
public int compare(Interval a, Interval b){
return a.end - b.end;
}
});
minHeap.offer(intervals[0]);
for (int i = 1; i < intervals.length; i++){
Interval interval = minHeap.poll();
if (intervals[i].start >= interval.end){
interval.end = intervals[i].end;
} else {
minHeap.offer(intervals[i]);
}
minHeap.offer(interval);
}
return minHeap.size();
}
}