public int minMeetingRooms(Interval[] intervals){
  if (intervals == null || intervals.length == 0) {
    return 0;
  }
  Arrays.sort(intervals,null);
  PriorityQueue<Interval> minHeap=new PriorityQueue<>(intervals.length,null);
  for (  Interval i : intervals) {
    if (!minHeap.isEmpty() && i.start >= minHeap.peek().end) {
      minHeap.poll();
    }
    minHeap.add(i);
  }
  return minHeap.size();
}

public int minMeetingRooms ( Interval [ ] intervals ) { if ( intervals == null || intervals . length == 0 ) { return 0 ; } Arrays . sort ( intervals , null ) ; PriorityQueue < Interval > minHeap = new PriorityQueue < > ( intervals . length , null ) ; for ( Interval i : intervals ) { if ( ! minHeap . isEmpty ( ) && i . start >= minHeap . peek ( ) . end ) { minHeap . poll ( ) ; } minHeap . add ( i ) ; } return minHeap . size ( ) ; }
sort , heap , greedy . always put the next starting meeting after the first ending meeting . if the start time overlaps with the nearest end time , need a new room . so , sort the meetings according to start time first . then for each interval in the array : 1 ) if min heap is empty , add to heap directly . 2 ) compare with the min ending time , if doesn ' t overlap , add this meeting after . 3 ) if overlap , need a new room .
