[抄题]:

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;
}
}

最新文章

  1. JS 中 Array.slice() 和 Array.splice()方法
  2. struts2 spring3.2 hibernate4.1 框架搭建 整合
  3. Mysql函数:Last_insert_id()语法讲解
  4. 解决PHP下导出csv乱码小记
  5. JAVA_Java中关于supper和this的理解
  6. Android 布局之RelativeLayout
  7. html5人物图片360度立体旋转
  8. [转载] 深入理解 docker ulimit
  9. Autel MaxiDAS DS708 Fatal Application Error illegal operation
  10. 什么是WebService
  11. android 回车键事件编程
  12. php 回调函数
  13. android 当目录路径从n层按back键退回到n-19层的时候,file manager自己主动退出
  14. Android binder学习一:主要概念
  15. 用户控件 RadioButtonList
  16. 58A
  17. (Alpha)Let&#39;s-个人贡献分
  18. C# 查看所有的隐藏文件
  19. 如何将TNJ的源代码添加到eclipse[转]
  20. Android :Activity、Adapter、List的初步学习

热门文章

  1. Ubuntu下安装为知笔记
  2. 伪元素:focus-within
  3. 好强大的页面功能调试(js调试,查找js绑定的事件)值得学习
  4. PS基础教程[4]如何载入笔刷
  5. bzoj 2282 消防
  6. 两种方式创建Maven项目【方式一】
  7. FastAdmin 将 PHP 框架升级到 ThinkPHP 5.1
  8. 利用 Excel 写 C51 的宏定义
  9. 软件开发中IT用语-日文和英文对照版
  10. IDC单IP绑定多域名(包括端口)