[抄题]:

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.

For example,
Given [[0, 30],[5, 10],[15, 20]],
return false.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

merge interval

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. Interval是一种结构,不是数组,不用加[]
  2. arrays.sort(具体对象+ comparator);

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

sort函数中包括comparator结构体,结构体中包括compare方法

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

comparator三部曲忘了怎么写了:sort函数中包括comparator结构体,结构体中包括compare方法

[关键模板化代码]:

//sort
Arrays.sort(intervals, new Comparator<Interval>() {
public int compare(Interval a, Interval b) {
return a.start - b.start;
}
});

[其他解法]:

[Follow Up]:

253. Meeting Rooms II PQ这个真的忘了啊

[LC给出的题目变变变]:

merge interval

[代码风格] :

/**
* Definition for an interval.
* public class Interval {
* int start;
* int end;
* Interval() { start = 0; end = 0; }
* Interval(int s, int e) { start = s; end = e; }
* }
*/
class Solution {
public boolean canAttendMeetings(Interval[] intervals) {
//cc
if (intervals == null) {
return false;
} //sort
Arrays.sort(intervals, new Comparator<Interval>() {
public int compare(Interval a, Interval b) {
return a.start - b.start;
}
}); //compare
for (int i = 0; i < intervals.length - 1; i++) {
if (intervals[i + 1].start < intervals[i].end) return false;
} return true;
}
}

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] 253. Meeting Rooms II 会议室 II

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

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

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

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

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

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

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

  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 会议室II

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

  8. 252. Meeting Rooms

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

  9. [LeetCode#252] Meeting Rooms

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

随机推荐

  1. POJ 1265 Area (pick定理)

    题目大意:已知机器人行走步数及每一步的坐标变化量,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:叉积求面积,pick定理求点. pick定理:面积=内部点数+边上点数/2-1 ...

  2. [QT][待解决问题]对话框ui载入卡顿问题

    电脑运行环境:win7 + qt-opensource-windows-x86-mingw530-5.8.0源码是 < Qt快速入门系列教程目录 > 第3篇 Qt5基础(三)Qt登录对话框 ...

  3. 剑指offer-第五章优化时间和空间效率(从1到n的整数中1出现的次数)

    题目:输入一个整数n,从1到n这n个十进制整数中1出现的次数. 思路1:对1到n中的任意一个数i对其进行求余数来判断个位是否为1,然后再求除数,判断十位是否为1.统计出1的个数.然后对1到n用一个循环 ...

  4. Windows下查看什么进程占用文件

    任务管理器→性能Tab→资源管理器→CPU→关联的句柄后面的检索框中录入文件名(关键文件夹即可). 比如我的是在删除tomcat下面的WEB-INF文件出现问题:就输入WEB-INF:mygod,发现 ...

  5. android通过查询电话号码获取联系人信息

    // 取得Intent中的頭像 ivShowImage = (ImageView) findViewById(R.id.call_log_detail_contact_img); //通话电话号码获取 ...

  6. the road of app test

    移动互联网测试——你应该要掌握的技能树 http://www.stuq.org/news/488 手机类型native app,hybrid app,web app http://www.uisdc. ...

  7. ThinkPHP5.1开启调试和错误提示

    app/config,php中找到 show_error_msg=false  改为True; 再将 'app_debug' => false 改为True;

  8. DM8127 更改调试串口为UART2

    1.uboot修改 1)修改宏定义 /*include/config/ti8148_evm.h*/ #define CONFIG_SYS_NS16550_COM2 0x48024000 #define ...

  9. codeforce 977 F. Consecutive Subsequence

    F. Consecutive Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  10. JAVA中跨平台分隔符

    在Windows下的路径分隔符和Linux下的路径分隔符是不一样的,当直接使用绝对路径时,跨平台会暴出“No such file or diretory”的异常. 比如说要在temp目录下建立一个te ...