当前位置:网站首页>Leetcode 729. My schedule I (provides an idea)
Leetcode 729. My schedule I (provides an idea)
2022-06-27 10:59:00 【I'm not xiaohaiwa~~~~】
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 .
Code:
class MyCalendar {
public:
MyCalendar() {
}
bool book(int start, int end) {
for(int i=start;i<end;i++)
{
if(find(vec.begin(),vec.end(),i)!=vec.end())
{
return false;
}
}
for(int i=start;i<end;i++)
{
vec.push_back(i);
}
return true;
}
private:
vector<int>vec;
};
/** * Your MyCalendar object will be instantiated and called as such: * MyCalendar* obj = new MyCalendar(); * bool param_1 = obj->book(start,end); */
边栏推荐
- [tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (I)
- Change PIP mirror source
- 直播电子商务应用程序开发需要什么基本功能?未来发展前景如何?
- Introduction to the use of Arduino progmem static storage area
- 以后发现漏洞,禁止告诉中国!
- Cross cluster deployment of helm applications using karmada [cloud native open source]
- C語言學習-Day_04
- JS file upload and download
- Dimitt's law
- [tcapulusdb knowledge base] Introduction to tmonitor background one click installation (II)
猜你喜欢
【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)
Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)
Analysis of mobile ar implementation based on edge computing (Part 2)
What is the experience of telecommuting in a foreign company| Community essay solicitation
Oracle multi table query
Oracle-多表查询
Learning notes - data set generation
直播電子商務應用程序開發需要什麼基本功能?未來發展前景如何?
【TcaplusDB知识库】Tmonitor单机安装指引介绍(二)
How to deploy jupyterlab in methodot?
随机推荐
Co jump
Support system of softswitch call center system
Flutter wechat sharing
中科院微生物所招聘青年PI 20位,2百万安家费,千万启动经费(长期有效)
Exception in Chinese character fuzzy query of MySQL database
实验笔记之——CARMEN (.log .clf)文件转换为rosbag
Feedforward feedback control system design (process control course design matlab/simulink)
Leetcode 522 longest special sequence ii[enumeration double pointer] leetcode path of heroding
.NET6接入Skywalking链路追踪完整流程
微软云 (Microsoft Cloud) 技术概述
Eureka core source code analysis
If you find any loopholes later, don't tell China!
Ubuntu手动安装MySQL
【TcaplusDB知识库】Tmonitor单机安装指引介绍(二)
Oracle trigger stored procedure writes at the same time
使用Karmada实现Helm应用的跨集群部署【云原生开源】
Test how students participate in codereview
Leetcode 729. 我的日程安排表 I(牛逼,已解决)
[tcapulusdb knowledge base] tcapulusdb Model Management Introduction
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)