leetcode_253_会议室 II
程序员文章站
2022-06-03 09:56:59
...
class Solution {
public int minMeetingRooms(int[][] intervals) {
if (intervals == null || intervals.length == 0)
return 0;
PriorityQueue<Integer> heap = new PriorityQueue<Integer>();
Arrays.sort(intervals, (o1, o2) -> o1[0] - o2[0]);
heap.add(intervals[0][1]);
for (int i = 1; i < intervals.length; i++) {
if (heap.peek() <= intervals[i][0]) {
heap.remove();
}
heap.add(intervals[i][1]);
}
return heap.size();
}
}
class Solution {
public int minMeetingRooms(int[][] intervals) {
if (intervals == null || intervals.length == 0)
return 0;
int[] starts = new int[intervals.length];
int[] ends = new int[intervals.length];
for (int i = 0; i < intervals.length; i++) {
starts[i] = intervals[i][0];
ends[i] = intervals[i][1];
}
Arrays.sort(starts);
Arrays.sort(ends);
int count = 0;
int endIdx = 0;
for (int start : starts) {
if (start >= ends[endIdx]) {
endIdx++;
} else {
count++;
}
}
return count;
}
}
下一篇: Docker镜像创建、数据管理与网络通信
推荐阅读
-
硬盘各种接口IDE、SATA与SATA II的优缺点分析
-
全球最轻14英寸笔记本!华硕灵珑II开卖:9999元
-
金邦发布EVO X II系列内存:专为AMD三代锐龙优化
-
惠普暗影精灵II代Pro内部做工怎么样?惠普暗影精灵II代Pro拆机详细评测图解
-
巨兽重生:酷冷至尊发布Cosmos II 25周年版机箱:双飞翼
-
【LeetCode】Two Sum & Two Sum II - Input array is sorted & Two Sum IV - Input is a BST
-
LeetCode454题四数相加 II
-
惠普暗影精灵II代Plus升级版值得买吗?暗影精灵II代Plus升级版全面深度评测
-
RX Vega II上了16GB HBM2显存 黄仁勋表示GDDR6更合适
-
Mssql高级注入笔记II