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会议室有冲突吗的更多相关文章

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

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

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

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

  3. [LeetCode#252] Meeting Rooms

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

  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. [LeetCode] Meeting Rooms 会议室

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

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

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

  7. 252. Meeting Rooms 区间会议室

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

  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. 【LeetCode】252. Meeting Rooms 解题报告(C++)

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

随机推荐

  1. 经典论文翻译导读之《Google File System》(转)

    [译者预读] GFS这三个字母无需过多修饰,<Google File System>的论文也早有译版.但是这不妨碍我们加点批注.重温经典,并结合上篇Haystack的文章,将GFS.TFS ...

  2. jquery Load方法的重要点

    一个非常重要而且很容易忽视的问题就是:你是否load进了你必须load的元素,是否有的没有load进来,打开firebug查看一下

  3. Shell函数使用方法

    Shell函数是一组命令集或语句组成一个可用块.利用函数可以简化脚本编写.函数要求先定义再使用,调用函数时直接使用函数名即可.这里主要介绍shell编程中函数定义.调用.获取函数参数以及获取函数返回值 ...

  4. python中求两个List的交集、并集和差集

    直接上代码,有三种方法,第三种调用库函数效率最高 # ! /usr/bin/env python # encoding:utf-8 if __name__ == '__main__': a = [1, ...

  5. 如何將字串yyyyMMddHHmmss轉成Datetime呢?

    有朋友在FB上問到,他們將日期的分隔符號都置換成空字串後的字串,要如何將它再轉回成DateTime呢? 例如日期 2013/04/02 14:08:37 會轉成 20130402140837 . 要如 ...

  6. 百度开放平台连接MySQL数据库

    在百度开放平台创建了MySQL数据库后只知道数据库名称,可以通过下面的方法进行连接: public function connect(){ $_server = getenv('HTTP_BAE_EN ...

  7. web访问命令行

    https://github.com/yudai/gotty go get github.com/yudai/gotty gotty -p 8000 -w kubectl exec -it mysql ...

  8. the type java.io.ObjectInputStream cannot be resolved. It is indirectly......

    问题的原因: 配置tomcat7.0的时候自己设置了jre的版本1.8,而没有用myeclipse10自带的jre1.6,导致了出现了差错! 两种解决的办法: 1.点击windows--->pr ...

  9. asp.net 将数据导成Excel文件

    思路:和word红头文件一样,采用xml格式的模板文件,再替换模板中设置好的标签就可以了.参考网址:http://www.cnblogs.com/tzy080112/p/3413938.html pu ...

  10. metasploitable使用

    DVWA默认的用户有5个,用户名密码如下(一个足以): admin/password gordonb/abc123 1337/charley pablo/letmein smithy/password