当前位置:网站首页>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);
*/
边栏推荐
- 【无标题】
- Web服务连接器:Servlet
- Software test interview questions - Test Type
- ContentType的作用
- wib3.0 跨越,在跨越(ง •̀_•́)ง
- GTSAM中ISAM2和IncrementalFixedLagSmoother说明
- LTE CSFB process
- 关于 PHP 启动 MongoDb 找不到指定模块问题
- Usage of test macro of GTEST
- Investment strategy discussion and market scale prediction report of China's solid state high power amplifier industry from 2022 to 2028
猜你喜欢
H3C firewall rbm+vrrp networking configuration
[happy Spring Festival] if you feel happy, dance
[paper reading] nflowjs: synthetic negative data intensive anomaly detection based on robust learning
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
HCIA复习
Sqlmap tutorial (III) practical skills II
数学三大核心领域概述:代数
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
Is it difficult for an information system project manager?
C language learning notes (mind map)
随机推荐
P问题、NP问题、NPC问题、NP-hard问题详解
Function of activation function
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
[web security] nodejs prototype chain pollution analysis
Commodity price visualization
Database: ODBC remote access SQL Server2008 in oracel
Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
Station B, Master Liu Er - dataset and data loading
The usage and difference between strlen and sizeof
Winter 2021 pat class B problem solution (C language)
Luogu [Beginner Level 4] array p1427 number game of small fish
Amazon Engineer: eight important experiences I learned in my career
Overview of three core areas of Mathematics: geometry
[untitled]
数学三大核心领域概述:几何
Grant Yu, build a web page you want from 0
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
A complete collection of necessary learning websites for office programmers
请求转发与重定向