当前位置:网站首页>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); */
边栏推荐
- Working at home is more tiring than going to work at the company| Community essay solicitation
- Easy to understand Laplace smoothing of naive Bayesian classification
- 【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
- Use of bufferedwriter and BufferedReader
- [noodle classic] Yunze Technology
- Future & CompletionService
- 2021 CSP J2入门组 CSP-S2提高组 第2轮 视频与题解
- Red envelope rain: a wonderful encounter between redis and Lua
- 感应电机直接转矩控制系统的设计与仿真(运动控制matlab/simulink)
- Openpyxl table reading instance
猜你喜欢
If you find any loopholes later, don't tell China!
[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction
Une compréhension facile de la simplicité de la classification bayésienne du lissage laplacien
Win10 shortcut key sorting
leetcode:522. Longest special sequence II [greed + subsequence judgment]
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)
[200 opencv routines] 212 Draw a slanted rectangle
【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.1 生成树协议(Spanning Tree Protocol (STP))
Analysis of mobile ar implementation based on edge computing (Part 2)
随机推荐
闭包的常见问题
border影响父元素的高度-解决方案
[tcapulusdb knowledge base] tcapulusdb cluster management introduction
[tcapulusdb knowledge base] Introduction to new models of tcapulusdb
[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction
flutter 微信分享
2021 CSP J2 entry group csp-s2 improvement group round 2 video and question solution
go-zero微服务实战系列(七、请求量这么高该如何优化)
Quelles sont les fonctions de base nécessaires au développement d'applications de commerce électronique en direct? Quelles sont les perspectives d'avenir?
前馈-反馈控制系统设计(过程控制课程设计matlab/simulink)
数据库之元数据
Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
The tutor invites you to continue your doctoral study with him. Will you agree immediately?
Win10快捷键整理
Cross cluster deployment of helm applications using karmada [cloud native open source]
[noodle classic] Yunze Technology
Basic violin plot in R with plot
【TcaplusDB知识库】TcaplusDB机器初始化和上架介绍
Working at home is more tiring than going to work at the company| Community essay solicitation
【TcaplusDB知识库】TcaplusDB机型管理介绍