[leetcode]253. Meeting Rooms II 会议室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.
Example 1:
Input:[[0, 30],[5, 10],[15, 20]]
Output: 2
Example 2:
Input: [[7,10],[2,4]]
Output: 1
思路
| 0 ------------------------- 30 |
|5-----10|
|15---20|
1. if starts[i] > ends[endItr], which means current meeting starts right after, we can continue to use previous meeting room. All we need to do is update ends pointer
2. otherwies, starts[i] < ends[endItr], which means current meeting starts when previous meeting has not ended. Then we need a new room for current meeting.
代码
class Solution {
public int minMeetingRooms(Interval[] intervals) {
int[] starts = new int[intervals.length];
int[] ends = new int[intervals.length];
for(int i = 0; i< intervals.length; i++) {
starts[i] = intervals[i].start;
ends[i] = intervals[i].end;
}
Arrays.sort(starts);
Arrays.sort(ends);
int rooms = 0;
int endsItr = 0;
for(int i= 0; i< starts.length; i++) {
if(starts[i]<ends[endsItr])
rooms++;
else
endsItr++;
}
return rooms;
}
}
[leetcode]253. Meeting Rooms II 会议室II的更多相关文章
- [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] 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
Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...
- LeetCode 252. Meeting Rooms (会议室)$
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- 252. Meeting Rooms 区间会议室
[抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...
- [LeetCode] 252. Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- 【LeetCode】253. Meeting Rooms II 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+堆 日期 题目地址:https://leetco ...
- 253. Meeting Rooms II 需要多少间会议室
[抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...
- 253. Meeting Rooms II
题目: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
随机推荐
- Wordpress 加载 js 文件到底部
wp_enqueue_script wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string ...
- 多目标跟踪baseline methods
参考文献: MOTChallenge 2015: Towards a Benchmark for Multi-Target TrackingLaura Leal-Taix ´e, Anton Mila ...
- PHP write byte array to file
/********************************************************************************* * PHP write byte ...
- threading模块创建线程
什么是线程 (thread) 线程也是一种多任务编程方式,可以使用计算机的多核资源.线程被称为轻量级的进程. 线程特征 *线程计算机多核分配的最小单位 *一个进程可以包含多个线程 *线程也是一个运行的 ...
- ScrollView的基本用法丶代理方法
属性: - (void)viewDidLoad { [super viewDidLoad]; _scrollView.backgroundColor = [UIColor redColor]; //设 ...
- NET Core 实战:使用 NLog 将日志信息记录到 MongoDB
NET Core 实战:使用 NLog 将日志信息记录到 MongoDB https://www.cnblogs.com/danvic712/p/10226557.html ASP.NET Core ...
- 10013: 以一种访问权限不允许的方式做了一个访问套接字的尝试【WCF异常】
错误代码:10013 异常描述:侦听 IP 终结点=0.0.0.0:6666 时出现 TCP 错误(10013: 以一种访问权限不允许的方式做了一个访问套接字的尝试.). 解决方式:由于端口6666被 ...
- test20181018 B君的第一题
题意 分析 考场爆零做法 考虑dp,用\(f(i,j,0/1)\)表示i及其子树中形成j个边连通块的方案数,其中i是否向外连边. \(O(n^3)\),转移方程太复杂就打挂了. #include< ...
- LG3389 【模板】高斯消元法
题意 题目描述 给定一个线性方程组,对其求解 输入输出格式 输入格式: 第一行,一个正整数\(n\) 第二至\(n+1\)行,每行\(n+1\)个整数,为\(a_1, a_2 \cdots a_n\) ...
- Android SDK无法更新的问题解决办法
问题: SSL hostname in certificate didn't matchhostname in certificate didn't match: <dl-ssl.google. ...