当前位置:网站首页>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);
*/
边栏推荐
- GTSAM中李群的運用
- Practice sharing: how to safely and quickly migrate from CentOS to openeuler
- continue和break的区别与用法
- CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
- A complete collection of necessary learning websites for office programmers
- Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
- SQLMAP使用教程(三)实战技巧二
- Is it difficult for an information system project manager?
- 异常检测方法总结
- 【LeetCode】Day96-第一个唯一字符&赎金信&字母异位词
猜你喜欢
Detailed explanation of BF and KMP
数学三大核心领域概述:代数
Clock in during winter vacation
Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai
Sqlmap tutorial (III) practical skills II
properties文件
The usage and difference between strlen and sizeof
GTSAM中李群的运用
进程和线程的理解
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
随机推荐
continue和break的区别与用法
Commodity price visualization
Summary of data sets in intrusion detection field
isam2运行流程
Configuring OSPF GR features for Huawei devices
Implementation of linked list in address book management system
[web security] nodejs prototype chain pollution analysis
Some easy-to-use tools make your essay style more elegant
【论文代码】SML部分代码阅读
C language bubble sort
Arrays and collections
养了只小猫咪
Reading notes of effective managers
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
Hongliao Technology: Liu qiangdong's "heavy hand"
HCIA复习
数字三角形模型 AcWing 1015. 摘花生
ContentType的作用
Nodejs realizes the third-party login of Weibo
H3C S5820V2_5830V2交换机IRF2堆叠后升级方法