[LeetCode] Meeting Rooms I & II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.
For example,
Given [[0, 30],[5, 10],[15, 20]],
return false.
/**
* Definition for an interval.
* struct Interval {
* int start;
* int end;
* Interval() : start(0), end(0) {}
* Interval(int s, int e) : start(s), end(e) {}
* };
*/
class Solution {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
sort(intervals.begin(), intervals.end(), [](const Interval &a, const Interval &b) {
return a.start < b.start;
});
for (int i = ; i < intervals.size(); ++i) {
if (intervals[i].start < intervals[i-].end) return false;
}
return true;
}
};
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.
For example,
Given [[0, 30],[5, 10],[15, 20]],
return 2.
/**
* Definition for an interval.
* struct Interval {
* int start;
* int end;
* Interval() : start(0), end(0) {}
* Interval(int s, int e) : start(s), end(e) {}
* };
*/
class Solution {
public:
int minMeetingRooms(vector<Interval>& intervals) {
vector<pair<int, int>> schedule;
for (auto interval : intervals) {
schedule.push_back({interval.start, });
schedule.push_back({interval.end, -});
}
sort(schedule.begin(), schedule.end());
int cnt = , res = ;
for (auto s : schedule) {
if (s.second == ) ++cnt;
else --cnt;
res = max(res, cnt);
}
return res;
}
};
[LeetCode] Meeting Rooms I & II的更多相关文章
- [LeetCode] Meeting Rooms II 会议室之二
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- LeetCode Meeting Rooms II
原题链接在这里:https://leetcode.com/problems/meeting-rooms-ii/ Given an array of meeting time intervals con ...
- [LeetCode] Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- LeetCode Meeting Rooms
原题链接在这里:https://leetcode.com/problems/meeting-rooms/ Given an array of meeting time intervals consis ...
- [LeetCode] 253. Meeting Rooms II 会议室之二
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] 253. Meeting Rooms II 会议室 II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] 252. Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- Meeting Rooms II
Description Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2, ...
- meeting room I & II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
随机推荐
- 使用fuel6.0自己主动安装openstack-juno版本号(2)
上篇中fuel_master已经安装完毕.接下来我们介绍怎样新建一个openstack环境. 1,在web界面中新建openstack环境: 点击主界面的加入button,新建openstack环境. ...
- java如何实现不固定个数传参
CreateTime--2017年9月15日14:42:40 Author:Marydon java如何实现不固定个数传参(定义实参个数可变的方法) 参考链接:原文链接 传统方法:为这个方法定义一 ...
- 1253 Dungeon Master
题目链接: http://noi.openjudge.cn/ch0205/1253/ http://poj.org/problem?id=2251 总时间限制: 1000ms 内存限制: 65536 ...
- SElinux测试及排错
一.修改SElinux的状态 #sestatus --查看状态 #setenforce --临时修改 #setenforce #getenforce #vim /etc/selinux/config ...
- C++基础学习教程(六)----类编写的前情回想以及项目实战(1)
在開始类的编写之前我们依旧须要回想整理一下前面所说的内容,(前面尽管是一个自己定义数据类型的实现过程,可是内容有点繁杂). 先看一段代码: /** @file calssStruct.cpp */ / ...
- jsp+easyui+DataGrid 例子
转自:https://blog.csdn.net/l3922768721/article/details/51597977 导入js和css <%@ page language="ja ...
- Tensorflow高级封装
Tensorflow比较灵活,但是它提供的操作比较低级,于是许多封装库应运而生. slim 导入方式 import tensorflow as tf import tensorflow.contrib ...
- PHPNow升级PHP版本为5.3.5的方法(转)
PHPNow升级PHP版本为5.3.5的方法 原文:http://sharebar.org/1142.html 在WIN上有时候需要测试一些PHP程序,又不会自行独立配置环境,那么PHPNow是非常好 ...
- linux shell 脚本攻略学习20--awk命令入门详解
awk生于1977年,创始人有三个,分别为 Alfred Aho,Peter Weinberger, 和 Brian Kernighan,名称源于三个创始人的姓的首字母. 作用:处理文本文件. awk ...
- C# winform DataGridView 常见属性
C# winform DataGridView 属性说明① 取得或者修改当前单元格的内容 ② 设定单元格只读 ③ 不显示最下面的新行 ④ 判断新增行 ⑤ 行的用户删除操作的自定义 ⑥ 行.列的隐藏和删 ...