Meeting Rooms II
Description
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
Example1
Input: intervals = [(0,30),(5,10),(15,20)]
Output: 2
Explanation:
We need two meeting rooms
room1: (0,30)
room2: (5,10),(15,20)
Example2
Input: intervals = [(2,7)]
Output: 1
Explanation:
Only need one meeting room
思路:扫描线,建立事件。
/**
* Definition of Interval:
* public classs Interval {
* int start, end;
* Interval(int start, int end) {
* this.start = start;
* this.end = end;
* }
* }
*/ class Event{
int time;
int flag; Event(int t, int s) {
this.time = t;
this.flag = s;
}
} public class Solution {
/**
* @param intervals: an array of meeting time intervals
* @return: the minimum number of conference rooms required
*/
public static Comparator<Event> comp = new Comparator<Event>() {
public int compare(Event e1, Event e2) {
if (e1.time == e2.time) {
return e1.flag - e2.flag;
}
return e1.time - e2.time;
}
};
public int minMeetingRooms(List<Interval> intervals) {
List<Event> list = new ArrayList<>();
for (Interval i : intervals) {
list.add(new Event(i.start, 1));
list.add(new Event(i.end, 0));
} Collections.sort(list, comp);
int count = 0, ans = 0;
for (Event e: list) {
if (e.flag == 1) {
count++;
} else {
count --;
}
ans = Math.max(ans, count);
}
return ans;
}
}
Meeting Rooms 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] 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 ...
- 253. Meeting Rooms II
题目: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
- [LeetCode#253] Meeting Rooms II
Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...
- [Swift]LeetCode253.会议室 II $ 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 ...
- 253. Meeting Rooms II 需要多少间会议室
[抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...
随机推荐
- [转帖]TPC-C解析系列03_TPC-C基准测试之SQL优化
TPC-C解析系列03_TPC-C基准测试之SQL优化 http://www.itpub.net/2019/10/08/3330/ TPC-C是一个非常严苛的基准测试模型,考验的是一个完备的关系数据库 ...
- [转帖]一文尽懂 USB4
一文尽懂 USB4 https://www.ithome.com/0/451/062.htm 今年 3 月份,USB Promoter Group(领导小组)首次发布了 USB4 规范,即下一代 US ...
- python基础学习(十一)
22.类 # 类 class # 实例 实体 instance class Student: # 空语句 保持结构的完整性 pass jack = Student() jack.name = &quo ...
- Python 容器用法整理
本文整理几种基本容器:列表.元组.字典和集合的用法和collections中几种已经预先实现的容器数据结构:namedtuple(),双向链表deque,ChainMap,Counter,Ordere ...
- POJ 3233-Matrix Power Series( S = A + A^2 + A^3 + … + A^k 矩阵快速幂取模)
Matrix Power Series Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 20309 Accepted: ...
- Bigdecimal除法异常
1.异常信息摘要(详细请见文末): java.lang.ArithmeticException: Non-terminating decimal expansion; no exact represe ...
- J.U.C之AQS:阻塞和唤醒线程
此篇博客所有源码均来自JDK 1.8 在线程获取同步状态时如果获取失败,则加入CLH同步队列,通过通过自旋的方式不断获取同步状态,但是在自旋的过程中则需要判断当前线程是否需要阻塞,其主要方法在acqu ...
- 前端知识总结--ES6新特性
ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,已经在 2015 年 6 月正式发布了.它的目标,是使得 JavaScript 语言可以用来编写复杂的大型应 ...
- Thinkphp中的assign() 和 display()
说到 $this->assign() 与 $this->display()想必用过TP框架的都不陌生,那么今天我们就来说说他们的作用及其他用法. 先说 $this->assign( ...
- 记一次bypass某场景GD库及拓展分析
0x00 前言 gou楼兰师傅发来个站说是过不了gd库,问我有啥办法没有,给了他之前海贼师傅说的jpg_payload脚本,但是绕不过,问他拿了站点,写了个jpg_payload批量的fuzz脚本,f ...