当前位置:网站首页>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)

边栏推荐
- 微信小程序基本组件使用介绍
- Recursive construction of maximum binary tree
- [quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
- paddlepaddle 29 无模型定义代码下动态修改网络结构(relu变prelu,conv2d变conv3d,2d语义分割模型改为3d语义分割模型)
- Find the mode in the binary search tree (use medium order traversal as an ordered array)
- Topic not received? Try this
- QT learning 28 toolbar in the main window
- 基于Pytorch 框架手动完成线性回归
- Cnopendata list data of Chinese colleges and Universities
- 【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
猜你喜欢

Network learning (III) -- highly concurrent socket programming (epoll)

Force buckle 145 Binary Tree Postorder Traversal

2022 welder (elementary) judgment questions and online simulation examination

Avatary的LiveDriver试用体验

Linux server development, detailed explanation of redis related commands and their principles

让Livelink初始Pose与动捕演员一致

Uniapp mobile terminal forced update function

Introduction to basic components of wechat applet

Main window in QT learning 27 application

Use of JMeter
随机推荐
C language queue
Pytorch(六) —— 模型调优tricks
Linux server development, MySQL index principle and optimization
芯片资料 网站 易特创芯
paddlepaddle 29 无模型定义代码下动态修改网络结构(relu变prelu,conv2d变conv3d,2d语义分割模型改为3d语义分割模型)
ZCMU--1492: Problem D(C语言)
Merging binary trees by recursion
【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
[VHDL parallel statement execution]
Record a stroke skin bone error of the skirt
快速使用 Jacoco 代码覆盖率统计
Bugku CTF daily one question chessboard with only black chess
C语言二叉树与建堆
Es FAQ summary
数据库实时同步利器——CDC(变化数据捕获技术)
Complete linear regression manually based on pytoch framework
Roulette chart 2 - writing of roulette chart code
Explore dry goods! Apifox construction ideas
Empire CMS collection Empire template program general
Notes on PHP penetration test topics