当前位置:网站首页>[daily training] 729 My schedule I
[daily training] 729 My schedule I
2022-07-05 21:08:00 【Puppet__】
subject
Achieve one MyCalendar Class to store your schedule . If the schedule to be added does not cause Repeat Booking , You can store this new schedule .
When there is some time overlap between the two schedules ( For example, both schedules are in the same time ), It will produce Repeat Booking .
The schedule can use a pair of integers start and end Express , The time here is a half open interval , namely [start, end), The set of real Numbers x For the range of , start <= x < end .
Realization MyCalendar class :
MyCalendar() Initialize calendar object .
boolean book(int start, int end) 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 .
Example :
Input :
[“MyCalendar”, “book”, “book”, “book”]
[[], [10, 20], [15, 25], [20, 30]]
Output :
[null, true, false, true]
explain :
MyCalendar myCalendar = new MyCalendar();
myCalendar.book(10, 20); // return True
myCalendar.book(15, 25); // return False , This schedule cannot be added to the calendar , Because of time 15 Has been booked by another schedule .
myCalendar.book(20, 30); // return True , This schedule can be added to the calendar , Because the first schedule is booked at less than each time 20 , And does not include time 20 .
Tips :
0 <= start < end <= 109
Each test case , call book The maximum number of methods is 1000 Time .
Code
package dayLeetCode;
import java.util.ArrayList;
import java.util.List;
public class dayleetcode729 {
List<int[]> booked;
public dayleetcode729() {
booked = new ArrayList<>();
}
public boolean book(int start, int end) {
for (int[] arr : booked){
// There is intersection
if (arr[0] < end && start < arr[1]){
return false;
}
}
booked.add(new int[]{
start, end});
return true;
}
}
边栏推荐
- ArcGIS栅格重采样方法介绍
- R language [data management]
- 国外LEAD美国简称对照表
- Write an interface based on flask
- Learning robots have no way to start? Let me show you the current hot research directions of robots
- Talk about my fate with some programming languages
- Viewrootimpl and windowmanagerservice notes
- When a user logs in, there is often a real-time drop-down box. For example, entering an email will @qq com,@163. com,@sohu. com
- 教你自己训练的pytorch模型转caffe(三)
- selenium 查找b或p标签的内容
猜你喜欢
随机推荐
CLion配置visual studio(msvc)和JOM多核编译
判断横竖屏的最佳实现
Simple getting started example of Web Service
中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
sql系列(基础)-第二章 限制和排序数据
【日常训练--腾讯精选50】89. 格雷编码(看题解才会的)
终端安全能力验证环境搭建和渗透测试记录
ViewRootImpl和WindowManagerService笔记
Opérations de lecture et d'écriture pour easyexcel
postgis 安装地理信息扩展
第05章_存储引擎
ODPS 下一个map / reduce 准备
事项研发工作流全面优化|Erda 2.2 版本如“七”而至
序列联配Sequence Alignment
What are the requirements of UL 2043 test for drive housing in the United States?
Introduction of ArcGIS grid resampling method
教你自己训练的pytorch模型转caffe(三)
模式-“里氏替换原则”
Binary search