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. iOS 申请distribution证书, 公钥,私钥

    私钥只有在本机生成CSR文件的时候会产生,公钥会在CSR文件传给apple时,apple产生.

  2. maven ,添加加密算法,使用

    1:消息摘要:(数字指纹):既对一个任意长度的一个数据块进行计算,产生一个唯一指纹.MD5/SHA1发送给其他人你的信息和摘要,其他人用相同的加密方法得到摘要,最后进行比较摘要是否相同. MD5(Me ...

  3. [cocos2d-x]认识游戏开发(图)

    FreeMind的.mm文件下载: http://yunpan.cn/cfL3cm6CZkMSt (提取码:e01a)

  4. 10. Lambda表达式.md

    为了简化匿名内部类的代码,具体定义: 例如将9.内部类中的匿名内部类例子: 原来代码: //Main.java public class Main { public static void main( ...

  5. Hibernate学习笔记3.2(Hibernate组建映射)

    1.组建映射 可以存在一个表里面 Husband.java package com.bjsxt.hibernate; import javax.persistence.Embedded; import ...

  6. VC/VS2010中快捷键

    序号 热键 备注 1 F7 编译 2 Ctrl + F7 链接 3 Ctrl + F5 运行 4 F9 在光标处设置断点 5 F10 单步跟踪 6 F11 进入函数内部跟踪 7 Shift + F11 ...

  7. openstack常用命令

    共享镜像 glance member-create fa47923c-2d3b-4d71-80cf-a047ba3bf342 eb3913b9ae5f41b09f2632389a1958d8删除共享镜 ...

  8. mysql 数据库必备命令操作,入门练习一下

    mysql 数据库必备命令操作 show databases: 查看所有的数据库: create database jfedu: 创建名为jfedu数据库: use nihao: 进入jfedu数据库 ...

  9. 用Lucene4.5对中文文本建立索引

    这里需要完成一个能对txt文本建立索引,并能完成检索查询.完成这个功能,使用的是Lucene4.5,同时使用其自带的中文分析器. 准备工作是在一个文件夹里面建一些txt文件,这是我的文件结构: 首先要 ...

  10. jquery 滚动条位置的

    $('#fixedHead').width()//div的宽度 $('#fixedHead')[0].scrollWidth//滚动条的宽度 两者的差为滚动条的宽度 var b1=$("#d ...