当前位置:网站首页>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);
*/
边栏推荐
- Simulation volume leetcode [general] 1447 Simplest fraction
- 【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
- D - How Many Answers Are Wrong
- [eolink] PC client installation
- 浅谈专项测试之弱网络测试
- JMeter做接口测试,如何提取登录Cookie
- Full link voltage measurement: building three models
- Left matching principle of joint index
- [postman] the monitors monitoring API can run periodically
- 曼哈顿距离和-打印菱形
猜你喜欢
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
私人云盘部署
黑猫带你学UFS协议第4篇:UFS协议栈详解
Manhattan distance sum - print diamond
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
[postman] collections - run the imported data file of the configuration
oscp raven2靶机渗透过程
[postman] the monitors monitoring API can run periodically
JWT-JSON WEB TOKEN
[C language] string left rotation
随机推荐
LeetCode 739. 每日温度
Left matching principle of joint index
Simulation volume leetcode [general] 1219 Golden Miner
JDBC requset corresponding content and function introduction
oscp raven2靶机渗透过程
Postman核心功能解析-参数化和测试报告
黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
技术分享 | 常见接口协议解析
Manhattan distance and Manhattan rectangle - print back font matrix
基于JEECG-BOOT的list页面的地址栏参数传递
MySQL之数据类型
How to extract login cookies when JMeter performs interface testing
一文揭开,测试外包公司的真 相
[postman] dynamic variable (also known as mock function)
Reading notes of effective managers
Summary of the post of "Web Test Engineer"
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
The pit encountered by keil over the years
Data type of MySQL
MFC on the conversion and display of long string unsigned char and CString