Easiest Java Solution using count


  • 0
    public class Solution {
        public int minMeetingRooms(Interval[] intervals) {
            if(intervals.length == 0)
                return 0;
    
            PriorityQueue<Integer> q = new PriorityQueue<Integer>(intervals.length * 2, new Comparator<Integer>(){
                public int compare(Integer a, Integer b){
                    if(Math.abs(a) == Math.abs(b))
                        return a - b;
                    else
                        return Math.abs(a) - Math.abs(b);
                }});
    
            for(Interval i : intervals){
                q.add(i.start);
                q.add(-i.end);
            }
            
            int count = 0;
            int max = 0;
            while(!q.isEmpty()){
                int i = q.poll();
                if(i >= 0)
                    max = Math.max(max, ++count);
                else
                    count--;
            }
            return max;
        }
    }
    

Log in to reply
 

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