min heap. nlogn. Java. Easy solution


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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.