*LeetCode-Meeting Rooms II

首先interval数组按照start 排序 然后建立一个以end排序的priority queue 这样每次按照start的先后顺序入队,入队之前要把所有在这个start之前都结束的会议poll出来

每次更新room数量 

public class Solution {
    public int minMeetingRooms(Interval[] intervals) {
        Arrays.sort ( intervals, new Comparator<Interval>(){
            public int compare ( Interval int1, Interval int2 ){
                return int1.start - int2.start;
            }
        });
        PriorityQueue <Interval> que = new PriorityQueue<Interval>( new Comparator<Interval>(){
            public int compare ( Interval int1, Interval int2 ){
                return int1.end - int2.end;
            }
        });
        int rooms = 0;
        for ( int i = 0; i < intervals.length; i ++ ){
            while ( !que.isEmpty() && que.peek().end <= intervals[ i ].start ){
                que.poll();
            }
            que.offer ( intervals[ i ] );
            rooms = Math.max ( rooms, que.size() );
        }
        return rooms;
    }
}


你可能感兴趣的:(*LeetCode-Meeting Rooms II)