[leetcode]252. Meeting Rooms会议室有冲突吗
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.
Example 1:
Input:[[0,30],[5,10],[15,20]]
Output: false
Example 2:
Input: [[7,10],[2,4]]
Output: true
题目
给定一些区间,判断是否有重合。
还是挺实际的场景,经常在图书馆预定study room的系统,内部也应该是这个逻辑。 当有overlapping的时候,就会报错。

思路
任何一组intervals, 若当前start < 之前end,即出现了overlapping
代码
class Solution {
public boolean canAttendMeetings(Interval[] intervals) {
if(intervals == null || intervals.length==0) return true;
int []start = new int[intervals.length];
int []end = new int[intervals.length];
for(int i = 0; i<intervals.length;i++){
start[i] = intervals[i].start;
end[i] = intervals[i].end;
}
Arrays.sort(start);
Arrays.sort(end);
/* 任何一组intervals, 若当前start < 之前end,即出现了overlapping
| i-1 |
| i |
*/
for(int i = 1; i< start.length; i++){
if(start[i]<end[i-1]) return false;
}
return true;
}
}
[leetcode]252. Meeting Rooms会议室有冲突吗的更多相关文章
- [LeetCode] 252. Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- LeetCode 252. Meeting Rooms (会议室)$
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode#252] Meeting Rooms
Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...
- [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] 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 会议室之二
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]253. Meeting Rooms II 会议室II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- 【LeetCode】252. Meeting Rooms 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode ...
随机推荐
- 新装kafka与zookeeper配置
zookeeper配置 dataDir=/opt/kafka_2.11-2.0.0/data/zookeeper # 尽量不要放在tmp# the port at which the clients ...
- docker之docker-machine用法
转自:https://www.cnblogs.com/jsonhc/p/7784466.html docker-machine 是docker官方提供的docker管理工具.通过docker-mach ...
- ReactiveX 学习笔记(0)学习资源
ReactiveX 学习笔记 ReactiveX 学习笔记(1) ReactiveX 学习笔记(2)创建数据流 ReactiveX 学习笔记(3)转换数据流 ReactiveX 学习笔记(4)过滤数据 ...
- 使用karma做多浏览器的UI测试
avalon1.6开发得差不多,这次使用先进的开发理念进行开发,比如模块化,单元测试什么... ui测试是重要的一环,之前用阿里的totoro,但打开浏览器不方便.于是从webdrieverio, n ...
- 15.Colection集合和Iterator接口.md
目录 1.Collection 1.1概念 1.1遍历方法-Lambda表达式 1.2遍历方法-Iterator接口 1.3使用Lambda方法遍历Iterator接口 1.4使用Foreach方法遍 ...
- idea中pom文件需要添加的依赖
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉. --> <!-- IDEA的maven项目中,默认源代码目录下的xml等资源文件并不会在编译的时候一块 ...
- C++ AfxBeginThread的介绍/基本用法
AfxBeginThread 用户界面线程和工作者线程都是由AfxBeginThread创建的.现在,考察该函数:MFC提供了两个重载版的AfxBeginThread,一个用于用户界面线程,另一 ...
- 安装 protoc 的各种坑
首先下载 protoc 2.6.1 https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.g ...
- LINUX 设置 backspace为删除键
描述 :在linux/unix平台上的 sqlplus中,如果输错了字符,要想删除,习惯性的按下backspace键后,发现非但没有删除想要删掉的字符,还多出了两个字符^H. 原因:由于终端默认ctr ...
- shiro 入门
参考文章: https://www.cnblogs.com/maofa/p/6407102.html https://www.cnblogs.com/learnhow/p/9747134.html h ...