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] ...
随机推荐
- matlab中一些常用的函数
stem函数h = stem(x,y); %绘制火柴梗图 ,stem的工作原理是,根据一个x对应一个y,绘制火柴梗图.
- 8 函数类型——《Swift3.0从入门到出家
Swift语言中每一个函数都有它特定的数据类型,称其为函数类型 函数类型和基本数据类型一样,可以定义变量或者常量,可以定义函数形参,也可以做为函数的返回值类型 函数类型的格式为:参数列表的数据类型—& ...
- Oracle 11G RAC:生产环境下架构
转: it168网站 原创 作者:刘炳林 在真实环境搭建一套Oracle RAC就好比是一堂劳动课,劳动前需要准备好劳动工具,对劳动课内容有充分的认识;按照步骤一步一步进行,需要考虑劳动过程中可能遇 ...
- 在android开发中添加外挂字体
1.在项目目录中,右键app——New——Folder—— Assets Folder 2.把.ttf或者.oft文件拷进这个assets文件夹 3.在onCreate()中 Typeface typ ...
- spring-aop + memcached 的简单实现
一般情况下,java程序取一条数据是直接从数据库中去取,当数据库达到一定的连接数时,就会处于排队等待状态,某些在一定时间内不会发生变化的数据,完全没必要每次都从数据库中去取,使用spring-aop ...
- pytest命令行选项
-m 标记 代码加一个装饰器:@pytest.mark.run_bbc_test,命令行添加 -m run_bbc_test,执行带@pytest.mark.run_bbc_test的测试用例: -k ...
- 整数a整数b
namespace ConsoleApplication6{ class Program { static void Main(string[] args) { while (true) { Cons ...
- Java-API-Package:java.sql百科
ylbtech-Java-API-Package:java.sql百科 提供使用 JavaTM 编程语言访问并处理存储在数据源(通常是一个关系数据库)中的数据的 API.此 API 包括一个框架,凭借 ...
- win7 网站发布备注
1.更改 .NET Framework 版本(改原设置v2.0 为v4.0) 2.程序池设置 3.基本设置 4.Web.config (debug="false") <sys ...
- 阿里Java开发规范记录(一)
近日,从网上下载了阿里云栖社区发布的<阿里巴巴Java开发手册(正式版)>v1.1.0版.从编程以来,一直苦于没有相关的.全面的.靠谱的规范可以参考,有了这手册,日后编程也算是找到了依 ...