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. go1.8之安装配置

    说明: 之前学习过go语言(大概是0.9版本),后来更新太快,也没怎么使用,就荒废掉了,今年有项目需要用go开发,重新捡起. 这是我在学习go语言过程中整理的内容,这里记录下,也方便我以后查阅. 操作 ...

  2. Android学习笔记四:activity的四种启动模式

    Activity有四种启动模式:standard,singleTop,singleTask,singleInstance. 1.standard:标准启动模式 默认模式,这个模式下启动的Activit ...

  3. ES6学习笔记九:修饰器

    一:修饰器(Decorator)是一个函数,用来修改类的行为. 1)定义与使用 function 修饰器名(target) { //target是被修饰对象,可用target.xxx进行调用修改 } ...

  4. 【leetcode】solution in java——Easy4

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6415011.html 16:Invert Binary Tree 此题:以根为对称轴,反转二叉树. 思路:看到 ...

  5. 安装lr时无法将值Disable Script Debugger 写入注册表

    1. 运行“regedit”打开注册表编辑器. 2. 右键点击权限.HKEY_CURRENT_USER-Softwart-Microsoft-Internet Explorer-Main 3. 勾选e ...

  6. Spring Boot 使用Jar打包发布, 并使用 Embedded Jetty/Tomcat 容器

    Jar包发布 在项目pom.xml中, 如果继承了Spring Boot的starter parent, 那么默认已经包含打包需要的plugins了, 设置为jar就能直接打包成包含依赖的可执行的ja ...

  7. Javascript判断Crontab表达式是否合法

    这段时间在做Quartz任务调度,使用的Crontab表达式实现的.Crontab由前端页面输入,作为参数穿入后台. 虽然Quartz具有校验Crontab表达式的方法,如下: boolean cro ...

  8. T-Sql常用语句

    1.用bcp导出txt数据 DECLARE ), ) BEGIN , ), '/', '-'); SET @bcp = 'bcp WebStat.dbo.[PV_HIS_' + @date + '] ...

  9. http和websocket共用同一端口

    webpack热部署相关的插件 webpack-hot-middleware:是模块热替换插件,可以避免网页刷新.这个功能并不重要,因为我们可以手动刷新. webpack-dev-middleware ...

  10. ios实例开发精品文章推荐(8.5)

    IOS基础知识记录 IOS基础知识记录一        http://www.apkbus.com/android-131902-1-1.htmlIOS基础知识记录二        http://ww ...