当前位置:网站首页>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);
*/
边栏推荐
- Réflexions sur la sécurité des données (réimpression)
- 模拟卷Leetcode【普通】1218. 最长定差子序列
- Simulation volume leetcode [general] 1062 Longest repeating substring
- 曼哈顿距离与曼哈顿矩形-打印回字型矩阵
- Career advancement Guide: recommended books for people in big factories
- 黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
- Properties file
- Is the test cycle compressed? Teach you 9 ways to deal with it
- [Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
- 模拟卷Leetcode【普通】1447. 最简分数
猜你喜欢
Postman core function analysis - parameterization and test report
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
Left matching principle of joint index
Manage configuration using Nacos
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
Construction and integration of Zipkin and sleuth for call chain monitoring
自定义指定路由上的Gateway过滤器工厂
G - Supermarket
keil MDK中删除添加到watch1中的变量
随机推荐
Simulation volume leetcode [general] 1062 Longest repeating substring
Manhattan distance sum - print diamond
Nodejs realizes the third-party login of Weibo
F - true liars (category and search set +dp)
Web界面元素的测试
Simulation volume leetcode [general] 1405 Longest happy string
【Postman】测试(Tests)脚本编写和断言详解
Simulation volume leetcode [general] 1296 Divide an array into a set of consecutive numbers
模拟卷Leetcode【普通】1091. 二进制矩阵中的最短路径
Hypothesis testing learning notes
Manage configuration using Nacos
Leaflet map
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
对数据安全的思考(转载)
模拟卷Leetcode【普通】1249. 移除无效的括号
LeetCode 1200. 最小绝对差
selenium源码通读·9 |DesiredCapabilities类分析
Construction and integration of Zipkin and sleuth for call chain monitoring
LeetCode 732. 我的日程安排表 III