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],.. ...
随机推荐
- SpringBoot之分页插件PageHelper的使用
在springboot中使用PageHelper插件有两种较为相似的方式,接下来我就将这两种方式进行总结. 方式一:使用原生的PageHelper 1.在pom.xml中引入依赖 <depend ...
- Zuul【自定义Filter】
实际业务中,如果要自定义filter过滤器,只需集成ZuulFIlter类即可,该类是个抽象类,它实现了IZuulFIlter接口,我们需要实现几个方法,如下示例: import static org ...
- FFmpeg中AVFrame.linesize的含义
在第一节FFmpeg开发教程一.FFmpeg 版 Hello world中遇到一个问题,在保存YUV的时候,粗暴的使用: fwrite(buf, 1, xsize * ysize, f); 方式去拷贝 ...
- FPS 游戏实现D3D透视
FPS游戏可以说一直都比较热门,典型的代表有反恐精英,穿越火线,绝地求生等,基本上只要是FPS游戏都会有透视挂的存在,而透视挂还分为很多种类型,常见的有D3D透视,方框透视,还有一些比较高端的显卡透视 ...
- 怎样输出Hello World
方法一: 进入python交互模式, 然后使用: print()函数输出 方法二: 新建一个.py文件, 然后写入print()函数, 再使用python命令执行输出:
- 在论坛中出现的比较难的sql问题:41(循环替换 循环替换关键字)
原文:在论坛中出现的比较难的sql问题:41(循环替换 循环替换关键字) 所以,觉得有必要记录下来,这样以后再次碰到这类问题,也能从中获取解答的思路.
- 翻译-在10行代码之内创建容器化的.net core应用
本文翻译自Hans Kilian的文章 Creating a containerized .NET core application in less than 10 lines of code htt ...
- gradle上传jar包到maven公共仓库
首先这里说的中央仓库 是指的 https://issues.sonatype.org/ 而不是maven私服. 其次是使用gradle上传jar包,maven上传,网上有很多教程,这里不做赘述. 首选 ...
- mycat使用--schema配置
<?xml version="1.0"?> <!DOCTYPE schema SYSTEM "schema.dtd"> -<myc ...
- Android笔记(二十九) Android中的异步更新(一) Android中的线程
Java中的线程 1. 线程的两种实现方式 ①继承Thread类 ②实现Runnable接口 两者区别在于,Thread这个类的对象,代表的是一个线程,而Runnable的对象,代表的是线程体(也就是 ...