当前位置:网站首页>LeetCode 729. 我的日程安排表 I
LeetCode 729. 我的日程安排表 I
2022-07-06 06:02:00 【Sasakihaise_】
【有序集合】先看区间的范围达到10^9,因此不能通过start + 1,end - 1这种的差分数组来表示是否已经被覆盖。又因为这是在线查询(查询是动态的,并不是所有区间都插入才查询)因为无法进行离散化。所以考虑TreeMap进行区间的动态插入和判断。
按照左端点排序,对于新区间,查找<end(注意:这里end是开的,所以要查找<他)的最大key,判断value是否>start,如果>说明区间重合,否则插入即可。
区分:java中TreeMap有:floorKey(floorEntry),lowerKey(lowerEntry)两种方法,区别在于前者包含等于。同理ceilKey(highterKey)也是。
class MyCalendar {
// 有序集合 1:24 1:26
TreeMap<Integer, Integer> map = new TreeMap();
public MyCalendar() {
}
public boolean book(int start, int end) {
Integer key = map.lowerKey(end);
if (key != null) {
if (map.get(key) > start) {
return false;
}
}
map.put(start, end);
return true;
}
}
/**
* Your MyCalendar object will be instantiated and called as such:
* MyCalendar obj = new MyCalendar();
* boolean param_1 = obj.book(start,end);
*/
边栏推荐
- 关于 PHP 启动 MongoDb 找不到指定模块问题
- Amazon Engineer: eight important experiences I learned in my career
- 《卓有成效的管理者》读书笔记
- C language learning notes (mind map)
- 如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
- Cognitive introspection
- 【论文代码】SML部分代码阅读
- Grant Yu, build a web page you want from 0
- 进程和线程的理解
- Accélération de la lecture vidéo de l'entreprise
猜你喜欢
随机推荐
Idea new UI usage
H3C防火墙RBM+VRRP 组网配置
[untitled]
Summary of data sets in intrusion detection field
A complete collection of necessary learning websites for office programmers
How to recover Huawei router's forgotten password
查詢生產訂單中某個(些)工作中心對應的標准文本碼
[ram IP] introduction and experiment of ram IP core
養了只小猫咪
【无标题】
HCIA review
查询生产订单中某个(些)工作中心对应的标准文本码
数学三大核心领域概述:代数
Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
Station B, Mr. Liu Er - multiple logistic regression, structure 7
Grant Yu, build a web page you want from 0
Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
Gtest之TEST宏的用法
H3C firewall rbm+vrrp networking configuration
【eolink】PC客户端安装