当前位置:网站首页>[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;
}
}
边栏推荐
- leetcode:1139. The largest square bounded by 1
- XML modeling
- Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
- ts 之 属性的修饰符public、private、protect
- ts 之 泛型
- 研學旅遊實踐教育的開展助力文旅產業發展
- Test of incombustibility of cement adhesives BS 476-4
- leetcode:1139. 最大的以 1 为边界的正方形
- ViewRootImpl和WindowManagerService笔记
- CLion配置visual studio(msvc)和JOM多核编译
猜你喜欢
随机推荐
Open source SPL eliminates tens of thousands of database intermediate tables
Binary search
Opérations de lecture et d'écriture pour easyexcel
Longest swing sequence [greedy practice]
启牛2980有没有用?开户安全吗、
Hdu2377bus pass (build more complex diagram +spfa)
LeetCode: Distinct Subsequences [115]
@Validated基础参数校验、分组参数验证和嵌套参数验证
水泥胶黏剂BS 476-4 不燃性测试
js常用方法封装
poj 3414 Pots (bfs+线索)
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
Test of incombustibility of cement adhesives BS 476-4
Arcgis\qgis no plug-in loading (no offset) mapbox HD image map
Sequence alignment
Aitm 2-0003 horizontal combustion test
终端安全能力验证环境搭建和渗透测试记录
vant 源码解析 之深层 合并对象 深拷贝
systemd-resolved 开启 debug 日志
XML modeling








