[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],...] ...
随机推荐
- 在mysql中,如何改变列声明.
C 在mysql中,如何改变列声明. 修改表 - 修改列名 使用 CHANGE COLUMN 来修改列的名字,还必须 设置 列的数据类型 mysql> desc test_tab -> / ...
- WebGL编程指南案例解析之绘制一个点
<!DOCTYPE html> <html> <head> <title>webgl</title> <style type=&quo ...
- Centos 中扩展 软件源 的安装 之 Remi ( 为yum 扩展软件源 )
平时一般都是使用Ubuntu的,最近用起来Centos 发现软件安装方便不是很方便, 在安装过程中接触到了这么一个概念, 就是为yum 安装 扩展源, 这里下面要说的就是其中的 Remi ...
- ubuntu遇到的问题
昨天分辨率在装一个游戏时被更改了,改过之后,怎么都改不过来... 折腾了一下午,在配置文件中/etc/X11/xorg.conf.failsafe,但是网上都是/etc/X11/xorg.conf, ...
- BZOJ4917: [Lydsy1706月赛]Hash Killer IV(模拟)
4917: [Lydsy1706月赛]Hash Killer IV Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 327 Solved: 140[Su ...
- HDU3335 Divisibility Dilworth定理+最小路径覆盖
首先需要一些概念: 有向图,最小路径覆盖,最大独立集,Dilworth,偏序集,跳舞链(DLX).... 理解一: 对于DAG图,有:最大独立集=点-二分匹配数,二分匹配数=最小路径覆盖. 而无向图, ...
- geek网工作室主页------我的第一个小项目
传送门:袁咩咩的小小博客 很快,就到了大二的寒假,大学的生活就这样过去了接近一半,之前听说大二寒假会有项目什么的,已经准好了心理准备. 但第一次着手项目,还是有点小紧张 在这之前我已经看了一些框架,也 ...
- .NET工具软件收集
======================== ILSPY 官网: http://ilspy.net/ .NET Reflector 官网:http:/ ...
- NOIP模拟赛(洛谷11月月赛)
T1 终于结束的起点 题解:枚举啊... 斐波那契数 第46个爆int,第92个爆long long.... 发现结果一般是m的几倍左右....不用担心T. #include<iostream ...
- 如何解决前后端token过期问题
问题描述: 首先后端生成的token是有时限的,在一段时间后不管前端用户是否进行了访问后端的操作,后端的token都会过期,在拦截器阶段就会返回错误的请求:token过期,从而拿不到想要的请求数据. ...