Meeting Rooms

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;
}
};

Meeting Rooms II

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的更多相关文章

  1. [LeetCode] Meeting Rooms II 会议室之二

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  2. LeetCode Meeting Rooms II

    原题链接在这里:https://leetcode.com/problems/meeting-rooms-ii/ Given an array of meeting time intervals con ...

  3. [LeetCode] Meeting Rooms 会议室

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  4. LeetCode Meeting Rooms

    原题链接在这里:https://leetcode.com/problems/meeting-rooms/ Given an array of meeting time intervals consis ...

  5. [LeetCode] 253. Meeting Rooms II 会议室之二

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  6. [LeetCode] 253. Meeting Rooms II 会议室 II

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  7. [LeetCode] 252. Meeting Rooms 会议室

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  8. Meeting Rooms II

    Description Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2, ...

  9. meeting room I & II

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

随机推荐

  1. Java多线程之创建线程的三种方式比较

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6560057.html  一:继承Thread类创建线程 1:继承Thread类定义线程子类: 2:重写run( ...

  2. JNI 引用问题梳理(转)

    局部引用: JNI 函数内部创建的 jobject 对象及其子类( jclass . jstring . jarray 等) 对象都是局部引用,它们在 JNI 函数返回后无效: 一般情况下,我们应该依 ...

  3. cocos2d-js 3.0 屏幕适配方案 分辨率适应

    首先介绍一个api和相应的参数: cc.view.setDesignResolutionSize(1024, 768, cc.ResolutionPolicy.FIXED_WIDTH); 这里设置游戏 ...

  4. 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. 软考历程(5)——extend 与 include

    软考中涉及扩展与包括关系的辨认,先不说考试的事,扩展与包括关系是UML中非经常见.非常基础的一种关系,然而我发现非常多同学都特别easy混淆,甚至软考真题中都存在题目和答案有待商榷的地方.此篇博客实属 ...

  6. 饭后来份TempData,瞅瞅有啥料

    原本打算写一篇关于.NET下的分布式缓存的随笔,但是为了举一个实际的运用,就想把控制器(是ASP.NET MVC的)中的Session替换成使用分布式缓存来实现.如果你的网站最后是需要负载均衡的话,这 ...

  7. Libevent例子(二)

    服务端 #include<netinet/in.h> #include<stdio.h> #include<string.h> #include<event. ...

  8. 转:D3DXVec3TransformNormal() 与 3DXVec3TransformCoord() 的区别

    DirectX中有两个很相似的函数,输入与输出的参数格式完全一样,都是输入一个三维向量(D3DXVECTOR3)和一个矩阵(D3DXMATRIX),输出变换之后的向量(D3DXVECTOR3). 函数 ...

  9. 一个成功的 Git 分支模型

    在这篇文章中介绍的开发模型在大约一年前已经在我的私有项目和工作引入的,而且已经被证明是非常成功的.我想写一些关于这个模型的东西已经好一段时间了,但是一直苦于没有时间,不过现在可以了.我不想探讨任何项目 ...

  10. Python 由list转为dictionary

    Python 由list转为dictionary 例如: 原始的 list 形式为: session_item_data=[[100, [10, 11], [12, 13]], [101, [11, ...