当前位置:网站首页>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;
}
}
边栏推荐
- Android interview, Android audio and video development
- IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
- How to convert word into PDF? Word to PDF simple way to share!
- MySql中的longtext字段的返回问题及解决
- Reptile exercises (II)
- [Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
- 强化学习-学习笔记4 | Actor-Critic
- Mariadb root用户及普通用户的密码 重置
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- Postman core function analysis - parameterization and test report
猜你喜欢
The problem of returning the longtext field in MySQL and its solution
力扣 729. 我的日程安排表 I
C# 语言的高级应用
That's awesome. It's enough to read this article
司空见惯 - 英雄扫雷鼠
Hiengine: comparable to the local cloud native memory database engine
Reflection and imagination on the notation like tool
How to apply smart contracts more wisely in 2022?
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
#夏日挑战赛#数据库学霸笔记,考试/面试快速复习~
随机推荐
信息/数据
What are general items
The problem of returning the longtext field in MySQL and its solution
#夏日挑战赛#数据库学霸笔记,考试/面试快速复习~
Fuzor 2020軟件安裝包下載及安裝教程
HiEngine:可媲美本地的云原生内存数据库引擎
Reflection and imagination on the notation like tool
司空见惯 - 英雄扫雷鼠
Go deep into the underlying C source code and explain the core design principles of redis
Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
Cf:b. almost Terry matrix [symmetry + finding rules + structure + I am structural garbage]
Android面试,android音视频开发
acm入门day1
软件测试是干什么的?学习有啥要求?
【无标题】
测试的核心价值到底是什么?
Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
从零实现深度学习框架——LSTM从理论到实战【实战】
Debezium系列之:解析默认值字符集
基于FPGA的超声波测距