当前位置:网站首页>LeetCode 729. My schedule I
LeetCode 729. My schedule I
2022-07-06 06:23:00 【Sasakihaise_】
【 Ordered set 】 First, the range of the interval reaches 10^9, So it can't pass start + 1,end - 1 This kind of difference group indicates whether it has been covered . And because this is online inquiry ( Queries are dynamic , Not all intervals are inserted before querying ) Because it cannot be discretized . So consider TreeMap Carry out dynamic insertion and judgment of intervals .
Sort by left endpoint , For New Area , lookup <end( Be careful : here end It's open , So look for < He ) Maximum key, Judge value whether >start, If > Explain that the interval coincides , Otherwise, insert it .
distinguish :java in TreeMap Yes :floorKey(floorEntry),lowerKey(lowerEntry) The two methods , The difference is that the former contains equal to . Empathy ceilKey(highterKey) It's also .
class MyCalendar {
// Ordered set 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);
*/
边栏推荐
- MySQL之数据类型
- LeetCode 739. 每日温度
- JWT-JSON WEB TOKEN
- 【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
- 调用链监控Zipkin、sleuth搭建与整合
- Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
- QT: the program input point xxxxx cannot be located in the dynamic link library.
- 曼哈顿距离和-打印菱形
- Past and present lives of QR code and sorting out six test points
- Full link voltage measurement: building three models
猜你喜欢
【Postman】测试(Tests)脚本编写和断言详解
Customize the gateway filter factory on the specified route
[no app push general test plan
Digital triangle model acwing 1015 Picking flowers
How to extract login cookies when JMeter performs interface testing
基于JEECG-BOOT制作“左树右表”交互页面
F - true liars (category and search set +dp)
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
Play video with Tencent video plug-in in uni app
随机推荐
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
selenium源码通读·9 |DesiredCapabilities类分析
全链路压测:构建三大模型
基于JEECG-BOOT的list页面的地址栏参数传递
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
Selenium source code read through · 9 | desiredcapabilities class analysis
MFC on the conversion and display of long string unsigned char and CString
MFC 动态创建的对话框及改变控件的大小和位置
Simulation volume leetcode [general] 1109 Flight reservation statistics
[postman] collections - run the imported data file of the configuration
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
JDBC Requset 对应内容及功能介绍
MySQL之数据类型
B - The Suspects
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
Career advancement Guide: recommended books for people in big factories
LeetCode 739. 每日温度
How to extract login cookies when JMeter performs interface testing