[抄题]:

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. DataBase project physical design

    DataBase physical design //Table: /*student*/ create table student( id int not null primary key, /*学 ...

  2. phpcmsV9搜索分页数量

    phpcmsV9搜索结果自定义控制分页条数,具体方法: 打开搜索模型文件夹phpcms/modules/search/index.php, 找到第85行: $result = $this->db ...

  3. AtCoder Grand Contest 017 迟到记

    晚上去操场上浪. 回来以后看到好几个人开着 \(AtCoder\) 在打代码. ... ... 今天有 \(AtCoder\) 比赛 ? 管它呢, \(Kito\) 在切西瓜,先吃西瓜... 然后看 ...

  4. 对Servlet规范的蜻蜓点水

    现在我们大家基本都用struts或springmvc进行java web的开发,但我们都知道java web的核心技术是jsp servlet javabean的组合.因此很有必要知道servlet规 ...

  5. Android Studio 打包及引用 AAR(可能是史上最详细的 )

    https://www.jianshu.com/p/1777a634db5e Android Library(AAR) 的好处 Android 库在结构上与 Android 应用模块相同.它可以提供构 ...

  6. Google网站遭到域名劫持

    今天晚上,包括Google.com在内的绝大多数Google国际网站,例如Google.com.Gmail.Google Reader.Google Docs等,在中国部分省市均出现无法访问的情况. ...

  7. vba传递参数类型错误

    先来看看微软官方的说明: 目录内容 概要 解决方案 详细信息 重现问题的步骤 &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp; ...

  8. 求分数1+1/2+1/3+.....+1/n的值

    总结:自己理解错了的有以下几点: 1.s初始化的值是0.但数据类型最好定位double双精度类型 2.for循环里面的i<n.不要忘了等号,因为i作为分母,不能为0,所以从1开始, 3.在mai ...

  9. 使用 sysbench对mysql进行压力测试介绍之一

    sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试.数据库目前支持MySQL/Oracle/PostgreSQL.本文只是简单演示一下几种测试的用 ...

  10. CCPC2018-湖南全国邀请赛 K 2018

    K.2018 题目描述 Given a, b, c, d , find out the number of pairs of integers ( x, y ) where a ≤ x ≤ b, c ...