当前位置:网站首页>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);
*/
边栏推荐
- About PHP startup, mongodb cannot find the specified module
- What are the test sites for tunnel engineering?
- 假设检验学习笔记
- Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
- Arrays and collections
- Linux regularly backs up MySQL database
- IPv6 comprehensive experiment
- Usage of test macro of GTEST
- Network protocol model
- Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
猜你喜欢
High quality coding tool clion
H3C V7 switch configuration IRF
Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
功能安全之故障(fault),错误(error),失效(failure)
C language learning notes (mind map)
C language bubble sort
Investment strategy discussion and market scale prediction report of China's solid state high power amplifier industry from 2022 to 2028
Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
【无标题】
随机推荐
Station B Liu Erden softmx classifier and MNIST implementation -structure 9
MPLS test report
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
Database: ODBC remote access SQL Server2008 in oracel
【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测
[Thesis code] SML part code reading
Introduction to promql of # yyds dry goods inventory # Prometheus
【LeetCode】Day96-第一个唯一字符&赎金信&字母异位词
[happy Spring Festival] if you feel happy, dance
Request forwarding and redirection
Arrays and collections
Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
【无标题】
Is it difficult for an information system project manager?
Bit operation rules
Luogu [Beginner Level 4] array p1427 number game of small fish
Configuring OSPF GR features for Huawei devices
【C语言】字符串左旋
Overview of three core areas of Mathematics: geometry