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. springMVC设置不拦截静态资源的方法

    SpringMVC提供<mvc:resources>来设置静态资源,但是增加该设置如果采用通配符的方式增加拦截器的话仍然会被拦截器拦截,可采用如下方案进行解决: 方案一.拦截器中增加针对静 ...

  2. Python入门学习——PyQt5程序基本结构

    在学习python GUI部分时,一开始看书有点懵,看不懂框架,以下是个人学习所得(参考了别人的视频讲解),错误之处,望大家指教 #0.导入需要的包和模块from PyQt5.Qt import * ...

  3. php获取当前月的天数

    <?php //php获取当前月份的所有天数 $start_day = date('Ym01', time()); $end_day = date('Ymd', strtotime(" ...

  4. 全面优化MySQL

    MySQL性能瓶颈原因 硬件.系统因素 CPU 磁盘I/O 网络性能 操作系统争用 MySQL相关因素 数据库设计 索引.数据类型 应用程序性能 特定请求.短时事务 配置变量 缓冲区.高速缓存.Inn ...

  5. Scratch编程:躲开鲨鱼(五)

    “ 上节课的内容全部掌握了吗?反复练习了没有,编程最好的学习方法就是练习.练习.再练习.一定要记得多动手.多动脑筋哦~~” 01 — 游戏介绍 这是一款简单的小游戏,实现了用鼠标控制一条小海星在水里游 ...

  6. 匹配script标签及内容js代码的正则表达式

    <script>[\s\S]+?</script>

  7. 【转载】Intellij IDEA神器居然还有这些小技巧

    概述Intellij IDEA真是越用越觉得它强大,它总是在我们写代码的时候,不时给我们来个小惊喜.出于对Intellij IDEA的喜爱,我决定写一个与其相关的专栏或者系列,把一些好用的Intell ...

  8. Java 之 序列化流

    一.序列化概述 Java 提供了一种对象 序列化 的机制.用一个字节序列可以表示一个对象,该字节序列包含该 对象的数据 . 对象的类型 和 对象中存储的属性 等信息.字节序列写出到文件之后,相当于文件 ...

  9. English-培训6-Do you like rap?

  10. array_map 去除数组参数里面左右两端空格

    <?php class Test{ public function trimArray($params){ if (!is_array($params)) return trim($params ...