当前位置:网站首页>[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;
}
}
边栏推荐
- Using webassembly to operate excel on the browser side
- 序列联配Sequence Alignment
- ClickHouse 复制粘贴多行sql语句报错
- 终端安全能力验证环境搭建和渗透测试记录
- Aitm2-0002 12s or 60s vertical combustion test
- The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application
- Display DIN 4102-1 Class B1 fire test requirements
- MySQL ifnull usage function
- Introduction of ArcGIS grid resampling method
- Learning notes of SAS programming and data mining business case 19
猜你喜欢

Display DIN 4102-1 Class B1 fire test requirements

XML modeling

Five layer network protocol

MySQL InnoDB架构原理

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

珍爱网微服务底层框架演进从开源组件封装到自研

Influence of oscilloscope probe on signal source impedance

基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)

使用WebAssembly在浏览器端操作Excel

【案例】元素的显示与隐藏的运用--元素遮罩
随机推荐
Binary search
MySQL InnoDB架构原理
Careercup its 1.8 serial shift includes problems
Test of incombustibility of cement adhesives BS 476-4
Pytoch practice -- MNIST dataset handwritten digit recognition
ArcGIS栅格重采样方法介绍
Dictionary tree simple introductory question (actually blue question?)
PVC plastic sheets BS 476-6 determination of flame propagation properties
Opérations de lecture et d'écriture pour easyexcel
大二下个人发展小结
获取前一天的js(时间戳转换)
leetcode:1139. 最大的以 1 为边界的正方形
MySQL ifnull usage function
Display DIN 4102-1 Class B1 fire test requirements
判断横竖屏的最佳实现
Talk about my fate with some programming languages
SQL series (basic) - Chapter 2 limiting and sorting data
终端安全能力验证环境搭建和渗透测试记录
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
bazel是否有学习的必要