Share my simple 8 line Priority Queue solution


  • 0
    H
    public int minMeetingRooms(Interval[] intervals) {
            Arrays.sort(intervals,new Comparator<Interval>(){
                @Override
                public int compare(Interval a, Interval b){return (a.start==b.start)?a.end-b.end:a.start-b.start;}});
            PriorityQueue<Integer> pq = new PriorityQueue<>();
            for(Interval i : intervals){
                if(!pq.isEmpty()&&pq.peek()<=i.start)pq.poll();
                pq.offer(i.end);
            }
            return pq.size();
        }
    

Log in to reply
 

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