Share my java AC Solution


  • 0
    M

    public class Solution {

    public int minMeetingRooms(Interval[] intervals) {
        Arrays.sort(intervals, new Comparator<Interval>(){
           public int compare(Interval i1, Interval i2){
               return Integer.compare(i1.start, i2.start);
           } 
        });
        
        PriorityQueue<Integer> endtime = new PriorityQueue<>();
        
        for(Interval inter: intervals){
            if(endtime.isEmpty()){ endtime.add(inter.end);}
            else{
                int e = endtime.peek();
                if(e<= inter.start){  // Not overlapped
                    endtime.poll();  // update
                }
                endtime.add(inter.end); // add new end time
            }
        }
        return endtime.size();
    }
    

    }


Log in to reply
 

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