当前位置:网站首页>[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;
}
}
边栏推荐
- Sequence alignment
- leetcode:1755. 最接近目标值的子序列和
- Binary search
- Phpstudy Xiaopi's MySQL Click to start and quickly flash back. It has been solved
- vant 源码解析 event.ts 事件处理 全局函数 addEventListener详解
- @Validated基础参数校验、分组参数验证和嵌套参数验证
- Influence of oscilloscope probe on signal source impedance
- ODPs next map / reduce preparation
- 实现浏览页面时校验用户是否已经完成登录的功能
- leetcode:1755. Sum of subsequences closest to the target value
猜你喜欢
基于flask写一个接口
R语言【数据管理】
XML modeling
The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application
Pytorch实战——MNIST数据集手写数字识别
2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
基于vertx-web-sstore-redis的改造实现vertx http应用的分布式session
leetcode:1755. 最接近目标值的子序列和
leetcode:1755. Sum of subsequences closest to the target value
基于AVFoundation实现视频录制的两种方式
随机推荐
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
hdu2377Bus Pass(构建更复杂的图+spfa)
POJ 3414 pots (bfs+ clues)
Utils/index TS tool function
wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
PVC plastic sheets BS 476-6 determination of flame propagation properties
示波器探头对测量带宽的影响
序列联配Sequence Alignment
php中explode函数存在的陷阱
Introduction of ArcGIS grid resampling method
Learning robots have no way to start? Let me show you the current hot research directions of robots
Dictionary tree simple introductory question (actually blue question?)
js常用方法封装
Material design component - use bottomsheet to show extended content (II)
AITM2-0002 12s或60s垂直燃烧试验
实现浏览页面时校验用户是否已经完成登录的功能
sql系列(基础)-第二章 限制和排序数据
Display DIN 4102-1 Class B1 fire test requirements
Modifiers of attributes of TS public, private, protect
ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图