当前位置:网站首页>leetcode: 253. How many meeting rooms are required at least
leetcode: 253. How many meeting rooms are required at least
2022-08-04 14:36:00 【OceanStar's study notes】
题目来源
题目描述

题目解析
最小堆
分析:
- 这里一定要把所有会议全部安排完,所以一定需要遍历这些数组
- 首先,一堆会议时间是杂乱无章的,为了让其有序,我们可以将其排序,那么问题是以起始时间排序还是以终止时间排序?
- 思考,这道题我们要解决的问题是:当观察到一个会议时,需不需要另外安排会议室?
- 从这个思路来看,我们考虑的顺序是按照会议开始的时间,因此这里按照会议起始的时间来排序
- 排序后遇到的另一个问题是,当一个新会议开始的时候,我们要怎么确定这个时候是否有之前空出来的会议室
- 因此我们还要对会议的结束时间进行统计,每当一个会议开始,我们就去检查这个会议之前开始的会议的结束时间的最小值.所以我们可以维护一个最小堆用于记录结束时间.
小结:
- 先按照开始时间对这些数组进行排序
- 然后准备一个最小堆,这个最小堆维护的是当前会议之前开始的会议的结束时间.怎么维护呢?
int minMeetingRooms(std::vector<std::vector<int>>intervals){
if(intervals.empty()){
return 0;
}
int minRooms = 0;
std::sort(intervals.begin(), intervals.end(), [](std::vector<int> &l, std::vector<int> &r){
return l[0] < r[0];
});
std::priority_queue<int, std::vector<int>, std::greater<>> pq;
// 第一个会议肯定是需要排序的
pq.emplace(intervals[0][1]);
for (int i = 1; i < intervals.size(); ++i) {
// 有一个会议室空出来了
if(intervals[i][0] >= pq.top()){
// 如果当前会议start >= 之前的end
pq.pop(); // 把之前的房间空出来
}
pq.emplace(intervals[i][1]);
}
return minRooms;
}
边栏推荐
- 手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
- eyb:JWT介绍
- 【Web技术】1401- 图解 Canvas 入门
- 快解析结合千方百剂
- Oracle RAC环境下vip/public/private IP的区别
- CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
- 零基础可以转行软件测试吗 ?这篇文章告诉你
- 七夕邂逅爱,那人一定在
- idea去掉spark的日志
- [The Art of Hardware Architecture] Study Notes (1) The World of Metastability
猜你喜欢

Find My Technology | Prevent your pet from getting lost, Apple Find My technology can help you

用于X射线聚焦的复合折射透镜

Qt的QItemDelegate使用

化繁为简,聊一聊复制状态机系统架构抽象

leetcode:250. 统计同值子树

量化细胞内的信息流:机器学习时代下的研究进展

【 HMS core 】 【 Media 】 online video editing service 】 【 material can't show, or network anomalies have been Loading state

JCMsuite应用:倾斜平面波传播透过光阑的传输

MySQL【触发器】

centos7安装mysql急速版
随机推荐
手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
特殊品种的二次开户验资金额
Chinese valentine's day, of course, to learn SQL optimization better leave work early to find objects
[机缘参悟-60]:《兵者,诡道也》-1-开篇:“死“与“生“都是天道
[Opportunity Enlightenment-60]: "Soldiers, Stupid Ways"-1- Opening: "Death" and "Life" are the way of heaven
本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
How to install postgresql and configure remote access in ubuntu environment
xpath获取带命名空间节点注意事项
利用决策树找出最优特征组合
量化细胞内的信息流:机器学习时代下的研究进展
NPDP|作为产品经理,如何快速提升自身业务素养?
用于X射线聚焦的复合折射透镜
vim common operation commands
SLAM 05.视觉里程计-2-特征法
B. Construct a simple sequence (greedy)
Technology sharing | Mini program realizes audio and video calls
Find My技术|防止你的宠物跑丢,苹果Find My技术可以帮到你
Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market
Find My Technology | Prevent your pet from getting lost, Apple Find My technology can help you