当前位置:网站首页>Force buckle 729 My schedule I
Force buckle 729 My schedule I
2022-07-05 19:28:00 【Ruthless young Fisherman】
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 .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/my-calendar-i
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Method 1: simulation
Java Realization
class MyCalendar {
List<int[]> list;
public MyCalendar() {
list = new ArrayList<>();
}
public boolean book(int start, int end) {
end--; //
for (int[] var : list) {
int l = var[0], r = var[1];
if (start > r || end < l) continue;
return false;
}
list.add(new int[]{
start, end});
return true;
}
}
边栏推荐
- 不愧是大佬,字节大牛耗时八个月又一力作
- Reflection and imagination on the notation like tool
- JS解力扣每日一题(十二)——556. 下一个更大元素 III(2022-7-3)
- 建议收藏,我的腾讯Android面试经历分享
- Ultrasonic ranging based on FPGA
- 软件测试是干什么的?学习有啥要求?
- webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
- Summer Challenge database Xueba notes, quick review of exams / interviews~
- Fundamentals of shell programming (Part 8: branch statements -case in)
- Apprentissage du projet MMO I: préchauffage
猜你喜欢
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
What is the core value of testing?
微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
MMO項目學習一:預熱
【硬核干货】数据分析哪家强?选Pandas还是选SQL
The problem of returning the longtext field in MySQL and its solution
Ultrasonic ranging based on FPGA
Fuzor 2020软件安装包下载及安装教程
软件测试是干什么的?学习有啥要求?
随机推荐
Blue sky drawing bed Apple quick instructions
Postman核心功能解析-参数化和测试报告
The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
Can Leica capture the high-end market offered by Huawei for Xiaomi 12s?
软件测试工程师是做什么的?待遇前景怎么样?
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
在线协作产品哪家强?微软 Loop 、Notion、FlowUs
微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
集合
JAD的安装、配置及集成IDEA
Go语言 | 03 数组、指针、切片用法
PHP利用ueditor实现上传图片添加水印
安卓面试宝典,2022Android面试笔试总结
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
Ultrasonic ranging based on FPGA
flume系列之:拦截器过滤数据
Advanced application of C # language
关于 Notion-Like 工具的反思和畅想
Technology sharing | common interface protocol analysis