Meeting Rooms II

来源:互联网 发布:js时间戳有什么作用 编辑:程序博客网 时间:2024/04/30 05:24
/** * Definition for an interval. * public class Interval { *     int start; *     int end; *     Interval() { start = 0; end = 0; } *     Interval(int s, int e) { start = s; end = e; } * } */public class Solution {    public int minMeetingRooms(Interval[] intervals) {        if (intervals == null || intervals.length == 0) {            return 0;        }        Arrays.sort(intervals, new Comparator<Interval>(){            @Override            public int compare(Interval a, Interval b) {                return a.start - b.start;            }        });        PriorityQueue<Integer> queue = new PriorityQueue<>();        queue.offer(intervals[0].end);        for (int i = 1; i< intervals.length; i++) {            Interval a = intervals[i];            if (a.start >= queue.peek()) {                queue.poll();            }            queue.offer(a.end);        }        return queue.size();    }  }

0 0
原创粉丝点击