[leetcode]253. Meeting Rooms II 会议室II
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的更多相关文章
- [LeetCode] 253. Meeting Rooms II 会议室 II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [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
Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...
- LeetCode 252. Meeting Rooms (会议室)$
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- 252. Meeting Rooms 区间会议室
[抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...
- [LeetCode] 252. Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- 【LeetCode】253. Meeting Rooms II 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序+堆 日期 题目地址:https://leetco ...
- 253. Meeting Rooms II 需要多少间会议室
[抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...
- 253. Meeting Rooms II
题目: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
随机推荐
- django2 xadmin pip list
diff-match-patch 20121119Django 2.0.5django-crispy-forms 1.7.2django-formtools 2.1django-import-expo ...
- 《DSP using MATLAB》Problem 2.15
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- CentOS 7安装TigerVNC Server
http://blog.csdn.net/wamath/article/details/76003128 1. CentOS 7安装TigerVNC Server 本文介绍如何在CentOS 7上安装 ...
- SpringCloud初体验:二、Config 统一配置管理中心
Spring Cloud Config : 配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储.Git以及Subversion. 配置中心也区分为服务端和客户端,本次体 ...
- C BIN加密
#include <stdio.h> #include <string.h> #include <stdlib.h> #ifndef DWORD #define D ...
- TS流解析 二 *****
1.TS格式介绍 TS:全称为MPEG2-TS.TS即"Transport Stream"的缩写.它是分包发送的,每一个包长为188字节(还有192和204个字节的包).包的结构为 ...
- hudson插件说明
Artifactory Plugin:maven仓库管理工具 Backup plugin 可以备份hudson_home下所有文件,除了svncode.这个插件有问题,不能使用. Build Publ ...
- Devexpres下LookUpEdit绑定数据后会默认弹出数据框的解决办法
LookUpEdit绑定数据后会默认弹出数据框很不友好问题现象: 问题解决前的代码: lueManagement.Text = groupEntity.Name; 2 lueManagement.Ed ...
- bzoj4403 两个串
Description 兔子们在玩两个串的游戏.给定两个字符串S和T,兔子们想知道T在S中出现了几次, 分别在哪些位置出现.注意T中可能有“?”字符,这个字符可以匹配任何字符. Input 两行两个字 ...
- 思科、华为、H3C命令对照表
思科 华为 H3C 描述 no undo undo 取消/关闭 当前设置 show display display 查看.显示 exit quit quit 退回上级 hostname sysname ...