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

边栏推荐
- Chip information website Yite Chuangxin
- Linux server development, MySQL index principle and optimization
- Excel import function of jeesite form page
- UnityHub破解&Unity破解
- 2022 tea master (intermediate) examination questions and mock examination
- Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
- Padavan manually installs PHP
- LeetCode简单题之找到一个数字的 K 美丽值
- 快速使用 Jacoco 代码覆盖率统计
- Relevant data of current limiting
猜你喜欢

JSON data flattening pd json_ normalize

Network learning (II) -- Introduction to socket

Linux server development, MySQL transaction principle analysis

Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!

青龙面板-今日头条

Padavan manually installs PHP

JS复制图片到剪切板 读取剪切板

Linux server development, MySQL index principle and optimization

LeetCode中等题之我的日程安排表 I

【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
随机推荐
game攻防世界逆向
Use of JMeter
复杂网络建模(三)
LeetCode简单题之字符串中最大的 3 位相同数字
Zsh shell adds automatic completion and syntax highlighting
芯片 设计资料下载
Ansible
Find the mode in the binary search tree (use medium order traversal as an ordered array)
Thinkcmf6.0安装教程
数据库实时同步利器——CDC(变化数据捕获技术)
王爽 《汇编语言》之寄存器
ZCMU--1492: Problem D(C语言)
[step on the pit series] H5 cross domain problem of uniapp
Cnopendata geographical distribution data of religious places in China
Linux server development, redis source code storage principle and data model
uniapp 移动端强制更新功能
积分商城管理系统中应包含的四大项
C language flight booking system
Qt学习26 布局管理综合实例
【踩坑系列】uniapp之h5 跨域的问题