当前位置:网站首页>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);
*/
边栏推荐
- Summary of data sets in intrusion detection field
- Construction of yolox based on paste framework
- 《卓有成效的管理者》读书笔记
- 请求转发与重定向
- isam2运行流程
- [leetcode] day96 - the first unique character & ransom letter & letter ectopic word
- Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
- H3C S5820V2_5830V2交换机IRF2堆叠后升级方法
- Station B, Mr. Liu Er - multiple logistic regression, structure 7
- 养了只小猫咪
猜你喜欢
随机推荐
GTSAM中ISAM2和IncrementalFixedLagSmoother说明
[untitled]
Hypothesis testing learning notes
华为BFD的配置规范
Web service connector: Servlet
请求转发与重定向
Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure
[leetcode] day96 - the first unique character & ransom letter & letter ectopic word
【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测
【论文代码】SML部分代码阅读
Request forwarding and redirection
nodejs实现微博第三方登录
Function of contenttype
Database: ODBC remote access SQL Server2008 in oracel
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
isam2运行流程
【无标题】
Web服务连接器:Servlet
Raised a kitten
Accélération de la lecture vidéo de l'entreprise









