当前位置:网站首页>[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;
}
}
边栏推荐
- 从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
- 大二下个人发展小结
- Opérations de lecture et d'écriture pour easyexcel
- Introduction of ArcGIS grid resampling method
- How to send samples when applying for BS 476-7 display? Is it the same as the display??
- systemd-resolved 开启 debug 日志
- Careercup its 1.8 serial shift includes problems
- Material design component - use bottomsheet to show extended content (II)
- leetcode:1755. Sum of subsequences closest to the target value
- 示波器探头对信号源阻抗的影响
猜你喜欢

CLion配置visual studio(msvc)和JOM多核编译

【案例】元素的显示与隐藏的运用--元素遮罩

LeetCode_哈希表_困难_149. 直线上最多的点数

【案例】定位的运用-淘宝轮播图

浅聊我和一些编程语言的缘分

leetcode:1755. Sum of subsequences closest to the target value

Which is the best online collaboration product? Microsoft loop, notion, flowus

PVC 塑料片BS 476-6 火焰传播性能测定

Wood board ISO 5660-1 heat release rate mapping test

教你自己训练的pytorch模型转caffe(三)
随机推荐
Sequence alignment
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
大二下个人发展小结
MySQL InnoDB架构原理
2022-07-03-CKA-粉丝反馈最新情况
MYSQL IFNULL使用功能
Web Service简单入门示例
Generics of TS
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
珍爱网微服务底层框架演进从开源组件封装到自研
@Validated基础参数校验、分组参数验证和嵌套参数验证
ts 之 泛型
leetcode:1755. 最接近目标值的子序列和
vant 源码解析之 utils/index.ts 工具函数
Écrire une interface basée sur flask
Influence of oscilloscope probe on measurement bandwidth
示波器探头对测量带宽的影响
Deep merge object deep copy of vant source code parsing
Add ICO icon to clion MinGW compiled EXE file