当前位置:网站首页>Leetcode 729. 我的日程安排表 I(提供一种思路)
Leetcode 729. 我的日程安排表 I(提供一种思路)
2022-06-27 10:26:00 【我不是萧海哇~~~~】
实现一个 MyCalendar 类来存放你的日程安排。如果要添加的日程安排不会造成 重复预订 ,则可以存储这个新的日程安排。
当两个日程安排有一些时间上的交叉时(例如两个日程安排都在同一时间内),就会产生 重复预订 。
日程可以用一对整数 start 和 end 表示,这里的时间是半开区间,即 [start, end), 实数 x 的范围为, start <= x < end 。
实现 MyCalendar 类:
- MyCalendar() 初始化日历对象。
- boolean book(int start, int end) 如果可以将日程安排成功添加到日历中而不会导致重复预订,返回 true
。否则,返回 false 并且不要将该日程安排添加到日历中。
示例:
输入:
["MyCalendar", "book", "book", "book"]
[[], [10, 20], [15, 25], [20, 30]]
输出:
[null, true, false, true]
解释:
MyCalendar myCalendar = new MyCalendar();
myCalendar.book(10, 20); // return True
myCalendar.book(15, 25); // return False ,这个日程安排不能添加到日历中,因为时间 15 已经被另一个日程安排预订了。
myCalendar.book(20, 30); // return True ,这个日程安排可以添加到日历中,因为第一个日程安排预订的每个时间都小于 20 ,且不包含时间 20 。
提示:
- 0 <= start < end <= 10^9
- 每个测试用例,调用 book 方法的次数最多不超过 1000 次。
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); */
边栏推荐
- File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument
- [tcapulusdb knowledge base] tcapulusdb cluster management introduction
- JS array splicing "suggested collection"
- Eureka核心源码解析
- Easy to understand Laplace smoothing of naive Bayesian classification
- Working at home is more tiring than going to work at the company| Community essay solicitation
- User authentication technology
- C语言学习-Day_06
- 前馈-反馈控制系统设计(过程控制课程设计matlab/simulink)
- Change PIP mirror source
猜你喜欢

前馈-反馈控制系统设计(过程控制课程设计matlab/simulink)
![File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument](/img/08/2d4f425e6941af35616911672b6fed.png)
File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument
![[200 opencv routines] 211 Draw vertical rectangle](/img/57/5ff4ccb6f003e1ec6c49de8c8fde16.png)
[200 opencv routines] 211 Draw vertical rectangle

Oracle trigger stored procedure writes at the same time

The tutor invites you to continue your doctoral study with him. Will you agree immediately?

Une compréhension facile de la simplicité de la classification bayésienne du lissage laplacien

【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)

CPU design (single cycle and pipeline)

Future & CompletionService

CPU设计(单周期和流水线)
随机推荐
Analysis of mobile ar implementation based on edge computing (Part 2)
Cross cluster deployment of helm applications using karmada [cloud native open source]
Ubuntu手动安装MySQL
Exception in Chinese character fuzzy query of MySQL database
Reorganize common shell scripts for operation and maintenance frontline work
Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
上周热点回顾(6.20-6.26)
Introduction to the use of Arduino progmem static storage area
Memory compression for win10
2021 CSP J2 entry group csp-s2 improvement group round 2 video and question solution
[hcie-rs review mind map] - STP
记一次 .NET 某物管后台服务 卡死分析
flutter 微信分享
【TcaplusDB知识库】TcaplusDB机器初始化和上架介绍
oracle触发器 存储过程同时写入
On anchors in object detection
Leetcode to do questions
The tutor invites you to continue your doctoral study with him. Will you agree immediately?
数据库之元数据
Easy to understand Laplace smoothing of naive Bayesian classification