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的更多相关文章

  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] 253. Meeting Rooms II 会议室之二

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  4. [LeetCode] 253. Meeting Rooms II 会议室 II

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  5. 253. Meeting Rooms II

    题目: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...

  6. [LeetCode#253] Meeting Rooms II

    Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...

  7. [Swift]LeetCode253.会议室 II $ Meeting Rooms II

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  8. [leetcode]253. Meeting Rooms II 会议室II

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  9. 253. Meeting Rooms II 需要多少间会议室

    [抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...

随机推荐

  1. jdk 7&8 new features

    7 Diamond Operator(菱形操作符) You can omitted the type declaration of the right when working with Generi ...

  2. 【坑】SpringMvc 处理JSON 乱码

    文章目录 前言 方法 前言 在使用 springMvc 的时候,如果向前台返回 JSON 数据,JSON 中的中文会乱码: 即使你在配置了全局的信息编码拦截器,也无济于事: 原因大抵是,JSON 的内 ...

  3. 地址解析协议(ARP)

    地址解析协议(ARP) 地址解析协议(ARP)是指网络地址和MAC地址之间的转换 当一台主机需要向另一台主机发送数据时,需要知道目的主机的ip地址外还需要知道目的主机的mac地址.源主机首先会在自己的 ...

  4. Gitlab服务不能启动postgresql

    源博文:http://www.zxmseed.com/blog/911081 1.查看启动的服务 -sh-4.1$ gitlab-ctl status warning: gitlab-workhors ...

  5. oracle_job进程相关学习测试

    Oracle cjq0进程测试 测试流程: .CJQ进程不存在 .模拟问题处理 .问题总结 一.问题现象 CJQ0进程不存在 [root@adg1 ~]# ps -ef|grep cjq root : ...

  6. easyExcel用于导入导出

    1.添加依赖: <!-- 现在已经更新到1.1.2-beta5 --> <dependency> <groupId>com.alibaba</groupId& ...

  7. <a>的javascript+jquery编程实例之删除(定位节点与事件绑定)

    相关jquery方法 parent(), remove() //上传图片 article_create.js article_edit.js function uploadAttachment() { ...

  8. pinfinder

    pinfinder https://pinfinder.net https://github.com/gwatts/pinfinder 关于 Pinfinder是一个小型免费程序,可以使用iPhone ...

  9. 【转载】C#通过StartWith和EndWith方法判断字符串是否以特定字符开始或者结束

    C#开发过程中针对字符串String类型的操作是常见操作,有时候业务需要判断某个字符串是否以特定字符开头或者特定字符结束,此时就可使用StartsWith方法来判断目标字符串是否以特定字符串开头,通过 ...

  10. 互联网项目中mysql推荐(读已提交RC)的事务隔离级别

    [原创]互联网项目中mysql应该选什么事务隔离级别 Mysql为什么不和Oracle一样使用RC,而用RR 使用RC的原因 这个是有历史原因的,当然要从我们的主从复制开始讲起了!主从复制,是基于什么 ...