当前位置:网站首页>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); */
边栏推荐
- Leetcode 522 longest special sequence ii[enumeration double pointer] leetcode path of heroding
- Uniform Asymptotics by Alexei
- What basic functions are required for live e-commerce application development? What is the future development prospect?
- Cross cluster deployment of helm applications using karmada [cloud native open source]
- Experiment notes - Convert Carmen (.Log.Clf) file to rosbag
- [从零开始学习FPGA编程-47]:视野篇 - 第三代半导体技术现状与发展趋势
- C語言學習-Day_04
- 堆-堆排序-TopK
- Uniform Asymptotics by Alexei
- Error im002 when Oracle connects to MySQL
猜你喜欢

飞桨产业级开源模型库:加速企业AI任务开发与应用

LVI Sam summary

Future & CompletionService

If you find any loopholes later, don't tell China!

Oracle trigger stored procedure writes at the same time

【TcaplusDB知识库】TcaplusDB Tmonitor模块架构介绍

Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
Test how students participate in codereview

Design and Simulation of direct torque control system for induction motor (motion control matlab/simulink)

机器学习系统在生产中的挑战
随机推荐
oracle触发器 存储过程同时写入
One copy ten, CVPR oral is accused of plagiarizing a lot
Frequently asked questions about closures
VPT模型视频讲解
JS client storage
Leetcode 729. 我的日程安排表 I(牛逼,已解决)
记一次 .NET 某物管后台服务 卡死分析
For a moment, the ban of the US e-cigarette giant has been postponed, and products can be sold in the US for the time being
Eureka核心源码解析
Write it down once Net analysis of a property management background service stuck
软交换呼叫中心系统的支撑系统
【TcaplusDB知识库】TcaplusDB集群管理介绍
学习笔记之——数据集的生成
微软云 (Microsoft Cloud) 技术概述
[cloud enjoys freshness] community weekly · vol.68- Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + business realization
红包雨: Redis 和 Lua 的奇妙邂逅
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (I)
Oracle-多表查询
audiotrack与audioflinger
【云享新鲜】社区周刊·Vol.68-华为云招募工业智能领域合作伙伴,强力扶持+商业变现