[抄题]:

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. touch-action属性

    CSS属性 touch-action 用于指定某个给定的区域是否允许用户操作,以及如何响应用户操作(比如浏览器自带的划动.缩放等). /* Keyword values */touch-action: ...

  2. python学习之基本类型

    #我的第一个python程序 print("hello world"); #多行字符串 print("""\ Usage: thingy [OPTIO ...

  3. HihoCoder 1097 Prim算法

    1097 : 最小生成树一·Prim算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 最近,小Hi很喜欢玩的一款游戏模拟城市开放出了新Mod,在这个Mod中,玩家可以 ...

  4. C# null和" "的区别

    String str1 = null;   str引用为空 String str2 = "";      str引用一个空串 也就是null没有分配空间,""分 ...

  5. matlab中hdl coder 的使用

    今天摸索了一下hdl coder的使用方法,各个步骤主要是照猫画虎,有些地方还是不理解,先总结一下: 1.要想调用quartus或者Xilinx综合布局布线需要先设置,设置的方法有两种,命令窗口输入 ...

  6. 关于quartus工程添加文件的说明

    quartus工程中要添加bsf文件的话需要将源文件也一同添加进来,添加ip核需要添加qip文件,时序约束文件只有添加到工程中才有效果,而timequest分析时需要制定约束文件.

  7. WinForm Flicker闪屏解决方案

    开发WinForm 程序时经常会遇到闪屏的问题,这会给用户造成很差的使用体验,所以必须妥善解决好这个问题. 首先,我们先要找出闪屏的原因,就我目前遇到的问题而言,其原因真是五花八门. 主要的原因有:使 ...

  8. VS2010环境下MFC使用DataGrid绑定数据源

    如果MFC的软件中 使用DataGrid控件后,在别的电脑上不能运行行,需要拷贝一个 MSDATGRD.ocx 和msstdfmt.dll  文件在软件的目录中,并写一个批处理文件 reg.dat 文 ...

  9. SpringMvc入门一----介绍

    Spring Mvc简介: Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求 ...

  10. 32位机,CPU是如何利用段寄存器寻址的

    转自:http://blog.sina.com.cn/s/blog_640531380100xa15.html 32位cpu 地址线扩展成了32位,这和数据线的宽度是一致的.因此,在32位机里其实并不 ...