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

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

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

  2. [LeetCode] 253. Meeting Rooms II 会议室之二

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

  3. [LeetCode#253] Meeting Rooms II

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

  4. LeetCode 252. Meeting Rooms (会议室)$

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

  5. 252. Meeting Rooms 区间会议室

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

  6. [LeetCode] 252. Meeting Rooms 会议室

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

  7. 【LeetCode】253. Meeting Rooms II 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+堆 日期 题目地址:https://leetco ...

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

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

  9. 253. Meeting Rooms II

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

随机推荐

  1. Ethereum以太网搭建本地开放环境简明教程

    引言: 区块链技术的风起云涌预示着一个去中心化时代的来临,ethereum技术栈是目前业界最为应用广泛的基于区块链技术的技术方案,本文将记录如何基于本地环境来搭建私有区块链的开发环境. 部署私有区块链 ...

  2. bacnet ip转MQTT

    迈思德网关最新支持BACNET IP协议,可以将BACNET IP转换为MODBUS.MQTT.OPC等协议,与百度天工,阿里云等无缝对接. 支持AI.AO.DI.DO.AV.DV六个对象的读写.

  3. Leetcode 1024. Video Stitching

    class Solution: def helper(self,l,r,clips)->int: maxL,maxR=0,0 iL,iR=-1,-1 for i,c in enumerate(c ...

  4. CF1082D:Maximum Diameter Graph (简单构造)

    Graph constructive problems are back! This time the graph you are asked to build should match the fo ...

  5. 6款实用的硬盘、SSD固态硬盘、U盘、储存卡磁盘性能测试工具

    一.检测工具名称汇总 HDTune ATTO Disk Benchmark CrystalDiskMark AS SSD Benchmark Parkdale CrystalDiskInfo 二.各项 ...

  6. 离散数学:用C语言来判断集合存在的二元关系

    用C语言来判断是否满足自反,反自反,非自反,对称,反对称,非对称和传递性 也不知道写的对不对.没有大量验证,但是随便找的一些关系测试的没毛病,如果错了,欢迎各位大佬留言 #include<bit ...

  7. java自动装箱和自动拆箱

    启蒙:https://droidyue.com/blog/2015/04/07/autoboxing-and-autounboxing-in-java/ 1,比较:=比就和string一样比较地址,有 ...

  8. 简单遗传算法-python实现

    ObjFunction.py import math def GrieFunc(vardim, x, bound): """ Griewangk function &qu ...

  9. C# 转义字符 '\'反斜杠

    在代码中经常用到表示路径的字符串,如何正确转换反斜杠? 如要将"C:\123"转换成"C:\\123" 如何转换? 方法: string str="C ...

  10. 02 - Unit02:登录功能

    需求实现步骤 发送Ajax请求 服务器处理 Ajax回调处理 登录功能 发送Ajax请求 绑定事件:"登录"按钮的单击事件 获取参数:用户名userName和密码password ...