当前位置:网站首页>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)
边栏推荐
- 芯片资料 网站 易特创芯
- Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
- 2022 welder (elementary) judgment questions and online simulation examination
- 快解析内网穿透助力外贸管理行业应对多种挑战
- Li Kou interview question 04.01 Path between nodes
- game攻防世界逆向
- Example of file segmentation
- padavan手动安装php
- 青龙面板-今日头条
- ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
猜你喜欢
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
船载雷达天线滑环的使用
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Thinkcmf6.0安装教程
调用 pytorch API完成线性回归
uniapp 移动端强制更新功能
Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
王爽 《汇编语言》之寄存器
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
随机推荐
Myabtis_ Plus
Qt学习26 布局管理综合实例
Content of string
ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
OpenJudge NOI 2.1 1752:鸡兔同笼
Quickly use Jacobo code coverage statistics
【踩坑系列】uniapp之h5 跨域的问题
Cnopendata American Golden Globe Award winning data
QT learning 28 toolbar in the main window
Relevant data of current limiting
Main window in QT learning 27 application
Téléchargement des données de conception des puces
青龙面板--花花阅读
ZCMU--1492: Problem D(C语言)
Linux server development, MySQL process control statement
Example of file segmentation
Force buckle 145 Binary Tree Postorder Traversal
Blob 对象介绍
JSON data flattening pd json_ normalize
Lattice coloring - matrix fast power optimized shape pressure DP