当前位置:网站首页>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);
*/
边栏推荐
- Li Chuang EDA learning notes 12: common PCB board layout constraint principles
- 【C语言】qsort函数
- Practice sharing: how to safely and quickly migrate from CentOS to openeuler
- 【课程笔记】编译原理
- Redistemplate common collection instructions opsforvalue (II)
- Eigen sparse matrix operation
- Zoom through the mouse wheel
- isam2运行流程
- Redis6 cluster setup
- Arrays and collections
猜你喜欢

J'ai un chaton.

Seven imperceptible truths in software testing

Configuring OSPF GR features for Huawei devices

Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028

What are the test sites for tunnel engineering?

【eolink】PC客户端安装

MIT6.s081-2020 Lab2 System Calls

【C语言】字符串左旋

养了只小猫咪

Clock in during winter vacation
随机推荐
Seven imperceptible truths in software testing
网络协议模型
Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)
[ram IP] introduction and experiment of ram IP core
【C语言】qsort函数
LTE CSFB process
GTSAM中李群的運用
Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure
VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator
properties文件
假设检验学习笔记
wib3.0 跨越,在跨越(ง •̀_•́)ง
Luogu [Beginner Level 4] array p1427 number game of small fish
查詢生產訂單中某個(些)工作中心對應的標准文本碼
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
The usage and difference between strlen and sizeof
Bit operation rules
Huawei BFD configuration specification
【Postman】Collections配置运行过程
P问题、NP问题、NPC问题、NP-hard问题详解