当前位置:网站首页>Leetcode medium question my schedule I
Leetcode medium question my schedule I
2022-07-07 08:09:00 【·Starry Sea】
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 <= 10^9
Each test case , call book The maximum number of methods is 1000 Time .
source : Power button (LeetCode)
Their thinking
Record it in the simplest way .
class MyCalendar:
def __init__(self):
self.record=[]
def book(self, start: int, end: int) -> bool:
if not self.record:
self.record.append([start,end])
return True
else:
for i in self.record:
if i[0]<end and i[1]>start:
return False
self.record.append([start,end])
return True
# Your MyCalendar object will be instantiated and called as such:
# obj = MyCalendar()
# param_1 = obj.book(start,end)
边栏推荐
- Binary tree and heap building in C language
- 复杂网络建模(一)
- 王爽 《汇编语言》之寄存器
- 【无标题】
- 数据库实时同步利器——CDC(变化数据捕获技术)
- Es FAQ summary
- C language communication travel card background system
- The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
- DNS server configuration
- 【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
猜你喜欢
Qt学习27 应用程序中的主窗口
有 Docker 谁还在自己本地安装 Mysql ?
Cnopendata American Golden Globe Award winning data
Thinkcmf6.0安装教程
The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
Li Kou interview question 04.01 Path between nodes
Record a stroke skin bone error of the skirt
QT learning 26 integrated example of layout management
Call pytorch API to complete linear regression
Avatary的LiveDriver试用体验
随机推荐
Qt学习28 主窗口中的工具栏
复杂网络建模(二)
Qt学习27 应用程序中的主窗口
电池、电机技术受到很大关注,反而电控技术却很少被提及?
2022 tea master (intermediate) examination questions and mock examination
快解析内网穿透为文档加密行业保驾护航
LeetCode简单题之判断一个数的数字计数是否等于数位的值
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
uniapp 移动端强制更新功能
Network learning (II) -- Introduction to socket
Introduction à l'objet blob
Qt学习26 布局管理综合实例
Linux Installation MySQL 8.0 configuration
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after conne
青龙面板--花花阅读
paddlepaddle 29 无模型定义代码下动态修改网络结构(relu变prelu,conv2d变conv3d,2d语义分割模型改为3d语义分割模型)
offer收割机:两个长字符串数字相加求和(经典面试算法题)
QT learning 26 integrated example of layout management
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Cnopendata American Golden Globe Award winning data