当前位置:网站首页>[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;
}
}
边栏推荐
- R language [data management]
- [case] Application of positioning - Taobao rotation map
- 国外LEAD美国简称对照表
- Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w
- Sophomore personal development summary
- LeetCode_哈希表_困难_149. 直线上最多的点数
- Modifiers of attributes of TS public, private, protect
- 面试官:并发编程实战会吗?(线程控制操作详解)
- Determine the best implementation of horizontal and vertical screens
- 《SAS编程和数据挖掘商业案例》学习笔记# 19
猜你喜欢

基於flask寫一個接口

PVC plastic sheets BS 476-6 determination of flame propagation properties

基于flask写一个接口

Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme

教你自己训练的pytorch模型转caffe(一)

Clion configures Visual Studio (MSVC) and JOM multi-core compilation

LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line

2022-07-03-CKA-粉丝反馈最新情况

事项研发工作流全面优化|Erda 2.2 版本如“七”而至

示波器探头对信号源阻抗的影响
随机推荐
R language [data management]
Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
leetcode:1139. 最大的以 1 为边界的正方形
postgis 安装地理信息扩展
EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
ODPs next map / reduce preparation
实现浏览页面时校验用户是否已经完成登录的功能
Pytorch实战——MNIST数据集手写数字识别
事项研发工作流全面优化|Erda 2.2 版本如“七”而至
获取前一天的js(时间戳转换)
SYSTEMd resolved enable debug log
CareerCup它1.8 串移包括问题
Using webassembly to operate excel on the browser side
php中explode函数存在的陷阱
终端安全能力验证环境搭建和渗透测试记录
Test of incombustibility of cement adhesives BS 476-4
树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
Learning robots have no way to start? Let me show you the current hot research directions of robots
【日常训练】729. 我的日程安排表 I
Is it necessary for bazel to learn