[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 ...
随机推荐
- Java多线程之创建线程的三种方式比较
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6560057.html 一:继承Thread类创建线程 1:继承Thread类定义线程子类: 2:重写run( ...
- JNI 引用问题梳理(转)
局部引用: JNI 函数内部创建的 jobject 对象及其子类( jclass . jstring . jarray 等) 对象都是局部引用,它们在 JNI 函数返回后无效: 一般情况下,我们应该依 ...
- cocos2d-js 3.0 屏幕适配方案 分辨率适应
首先介绍一个api和相应的参数: cc.view.setDesignResolutionSize(1024, 768, cc.ResolutionPolicy.FIXED_WIDTH); 这里设置游戏 ...
- cocos2d-js 3.0 RC0 手动绑定 C++调用js,js调用C++ jsbinding
参考:http://www.tairan.com/archives/4902 参考文章是2.x版本的,对于3.0也许不合适了,没有深究. 代码:https://github.com/kenkozhen ...
- 软考历程(5)——extend 与 include
软考中涉及扩展与包括关系的辨认,先不说考试的事,扩展与包括关系是UML中非经常见.非常基础的一种关系,然而我发现非常多同学都特别easy混淆,甚至软考真题中都存在题目和答案有待商榷的地方.此篇博客实属 ...
- 饭后来份TempData,瞅瞅有啥料
原本打算写一篇关于.NET下的分布式缓存的随笔,但是为了举一个实际的运用,就想把控制器(是ASP.NET MVC的)中的Session替换成使用分布式缓存来实现.如果你的网站最后是需要负载均衡的话,这 ...
- Libevent例子(二)
服务端 #include<netinet/in.h> #include<stdio.h> #include<string.h> #include<event. ...
- 转:D3DXVec3TransformNormal() 与 3DXVec3TransformCoord() 的区别
DirectX中有两个很相似的函数,输入与输出的参数格式完全一样,都是输入一个三维向量(D3DXVECTOR3)和一个矩阵(D3DXMATRIX),输出变换之后的向量(D3DXVECTOR3). 函数 ...
- 一个成功的 Git 分支模型
在这篇文章中介绍的开发模型在大约一年前已经在我的私有项目和工作引入的,而且已经被证明是非常成功的.我想写一些关于这个模型的东西已经好一段时间了,但是一直苦于没有时间,不过现在可以了.我不想探讨任何项目 ...
- Python 由list转为dictionary
Python 由list转为dictionary 例如: 原始的 list 形式为: session_item_data=[[100, [10, 11], [12, 13]], [101, [11, ...