当前位置:网站首页>leetcode729. My schedule 1
leetcode729. My schedule 1
2022-07-04 10:16:00 【JoesonChan】
Problem description
Achieve one MyCalendar Class to store your schedule . If there is no other schedule for the time to be added , You can store this new schedule .
MyCalendar There is one book(int start, int end) Method . It means in start To end Add a schedule in time , Be careful , The time here is a half open interval , namely [start, end), The set of real Numbers x For the range of , start <= x < end.
When there is some time overlap between the two schedules ( For example, both schedules are in the same time ), There will be repeat bookings .
Every time you call MyCalendar.book When the method is used , If the schedule can be successfully added to the calendar without causing duplicate bookings , return true. otherwise , return false And don't add the schedule to the calendar .
Please follow the steps below to call MyCalendar class : MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)
Example 1:
MyCalendar();
MyCalendar.book(10, 20); // returns true
MyCalendar.book(15, 25); // returns false
MyCalendar.book(20, 30); // returns true
explain :
The first schedule can be added to the calendar .
The second schedule cannot be added to the calendar , Because of time 15 It has been scheduled by the first schedule .
The third schedule can be added to the calendar , Because the first schedule doesn't include time 20 .
explain :
Each test case , call MyCalendar.book The function is no more than 100 Time .
Call function MyCalendar.book(start, end) when , start and end The value range of is [0, 10^9].
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
public class MyCalendar1 {
TreeMap<Integer, Integer> treeMap = null;
public MyCalendar1() {
treeMap = new TreeMap<>(Comparator.naturalOrder());
}
public boolean book(int start, int end) {
if (end <= start) {
return false;
}
for (Map.Entry<Integer, Integer> entry : treeMap.entrySet()) {
if (start >= entry.getValue()) {
break;
}
if(end <= entry.getKey()){
continue;
}
if (start < entry.getValue() || end > entry.getKey()) {
return false;
}
}
treeMap.put(start, end);
return true;
}
}
边栏推荐
- Golang defer
- 今日睡眠质量记录78分
- Does any teacher know how to inherit richsourcefunction custom reading Mysql to do increment?
- What is devsecops? Definitions, processes, frameworks and best practices for 2022
- MySQL case
- View CSDN personal resource download details
- In the case of easyUI DataGrid paging, click the small triangle icon in the header to reorder all the data in the database
- Golang 类型比较
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- Hands on deep learning (42) -- bi-directional recurrent neural network (BI RNN)
猜你喜欢
Matlab tips (25) competitive neural network and SOM neural network
Normal vector point cloud rotation
六月份阶段性大总结之Doris/Clickhouse/Hudi一网打尽
对于程序员来说,伤害力度最大的话。。。
What are the advantages of automation?
A little feeling
Servlet基本原理与常见API方法的应用
JDBC and MySQL database
Nuxt reports an error: render function or template not defined in component: anonymous
PHP code audit 3 - system reload vulnerability
随机推荐
Exercise 8-10 output student grades (20 points)
Does any teacher know how to inherit richsourcefunction custom reading Mysql to do increment?
On Multus CNI
品牌连锁店5G/4G无线组网方案
【Day1】 deep-learning-basics
【OpenCV 例程200篇】218. 多行倾斜文字水印
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
Nuxt reports an error: render function or template not defined in component: anonymous
Hands on deep learning (III) -- Torch Operation (sorting out documents in detail)
查看CSDN个人资源下载明细
Exercise 8-7 string sorting (20 points)
Kotlin set operation summary
Golang Modules
Go context 基本介绍
AUTOSAR从入门到精通100讲(106)-域控制器中的SOA
Write a mobile date selector component by yourself
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
按键精灵打怪学习-识别所在地图、跑图、进入帮派识别NPC
2021-08-11 function pointer
有老师知道 继承RichSourceFunction自定义读mysql怎么做增量吗?