252. Meeting Rooms 区间会议室
[抄题]:
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
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
- Interval是一种结构,不是数组,不用加[]
- 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 区间会议室的更多相关文章
- LeetCode 252. Meeting Rooms (会议室)$
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] 253. Meeting Rooms II 会议室 II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] 252. Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] Meeting Rooms II 会议室之二
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [LeetCode] 253. Meeting Rooms II 会议室之二
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [leetcode]252. Meeting Rooms会议室有冲突吗
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- [leetcode]253. Meeting Rooms II 会议室II
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- 252. Meeting Rooms
题目: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
- [LeetCode#252] Meeting Rooms
Problem: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2] ...
随机推荐
- UVA11168 Airport
题意 PDF 分析 首先发现距离最短的直线肯定在凸包上面. 然后考虑直线一般方程\(Ax+By+C=0\),点\((x_0,y_0)\)到该直线的距离为 \[ \frac{|Ax_0+By_0+C|} ...
- sublime text3 中设置默认浏览器,并且设置快捷键
1.打开packageControl 对应快捷键 command + shift + p 2.输入install package 3.安装插件 SideBarEnhancements 4.安装了 ...
- JavaScript 冒号(:)详解
1.switch语句分支 2.?:三元表达式的false 3.声明对象直接量的成员 4.声明标签 1和2相信地球人都知道吧?如果有人不知道,那我改成地球上的程序员都知道,哈哈 3.对象直接量我们也经常 ...
- bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 http://poj.org/problem?id=2409 学习材料:https:/ ...
- ASP.NET WebApi通过自定义ControllerSelector来自定义Controller的选择
在web api中,我们可以通过给Cotroller类添加RoutePrefixAttribute来定义url与Controller之间的映射,但是有时候有一些特殊情况下,我们需要做一些特殊处理来将某 ...
- Maven构建跳过测试步骤
有时候我们不想再执行maven的package或者install命令时每次都执行test,那么可以在pom.xml里的build->pluginManagement->plugins新增如 ...
- FPGA中RAM使用探索
FPGA中RAM的使用探索.以4bitX4为例,数据位宽为4为,深度为4. 第一种方式,直接调用4bitX4的RAM.编写控制逻辑对齐进行读写. quartus ii 下的编译,资源消耗情况. 85C ...
- 几大PHP套件
UPUPW:http://www.upupw.net/ PHPStudy:http://www.phpstudy.net/ PHPNow:http://servkit.org/
- Spring 循环依赖
循环依赖就是循环引用,就是两个或多个Bean相互之间的持有对方,比如CircleA引用CircleB,CircleB引用CircleC,CircleC引用CircleA,则它们最终反映为一个环.此处不 ...
- 杂项-公司:摩根大通百科-un
ylbtech-杂项-公司:摩根大通百科 摩根大通集团(JPMorgan Chase & Co,NYSE:JPM:),2000年12月由J.P.摩根公司和大通-曼哈顿公司合并而成,是美国主要的 ...