当前位置:网站首页>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); */
边栏推荐
- C language learning day_ 05
- 三层架构中,数据库的设计在哪一层实现,不是在数据存储层吗?
- Metadata of database
- Brother sucks 590000 fans with his unique "quantum speed reading" skill: look at the street view for 0.1 seconds, and "snap" can be accurately found on the world map
- mongodb跨主机数据库拷贝以及常用命令
- Multi thread implementation rewrites run (), how to inject and use mapper file to operate database
- 2-4 installation of Nessus under Kali
- . Net
- C语言学习-Day_05
- 迪米特法则
猜你喜欢
Eureka core source code analysis

Explain the imaging principle of various optical instruments in detail

前馈-反馈控制系统设计(过程控制课程设计matlab/simulink)

Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)

TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.1 生成树协议(Spanning Tree Protocol (STP))

oracle触发器 存储过程同时写入

三层架构中,数据库的设计在哪一层实现,不是在数据存储层吗?

CPU design (single cycle and pipeline)

Future & CompletionService
![[hcie-rs review mind map] - STP](/img/b5/b89e59fe7f23bf23feeadb991acba7.png)
[hcie-rs review mind map] - STP
随机推荐
LVI Sam summary
[tcapulusdb knowledge base] tcapulusdb Model Management Introduction
LeetCode 522 最长特殊序列II[枚举 双指针] HERODING的LeetCode之路
迪米特法则
flutter 微信分享
Advantages and disadvantages of distributed file storage system
Ubuntu手动安装MySQL
Une compréhension facile de la simplicité de la classification bayésienne du lissage laplacien
Change PIP mirror source
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (I)
使用Karmada实现Helm应用的跨集群部署【云原生开源】
leetcode:968. Monitor the binary tree [tree DP, maintain the three states of each node's subtree, it is very difficult to think of the right as a learning, analogous to the house raiding 3]
C语言学习-Day_04
iMeta:高颜值绘图网站imageGP+视频教程合集,已被引360次(220625更新)
Explain the imaging principle of various optical instruments in detail
[cloud enjoys freshness] community weekly · vol.68- Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + business realization
并发,并行,异步,同步,多线程,互斥的概念
闭包的常见问题
C language learning day_ 05
12 necessary tools for network engineers