当前位置:网站首页>【日常训练】729. 我的日程安排表 I
【日常训练】729. 我的日程安排表 I
2022-07-05 21:03:00 【Puppet__】
题目
实现一个 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 <= 109
每个测试用例,调用 book 方法的次数最多不超过 1000 次。
代码
package dayLeetCode;
import java.util.ArrayList;
import java.util.List;
public class dayleetcode729 {
List<int[]> booked;
public dayleetcode729() {
booked = new ArrayList<>();
}
public boolean book(int start, int end) {
for (int[] arr : booked){
// 有交集
if (arr[0] < end && start < arr[1]){
return false;
}
}
booked.add(new int[]{
start, end});
return true;
}
}
边栏推荐
- Specification of protein quantitative kit for abbkine BCA method
- Learning robots have no way to start? Let me show you the current hot research directions of robots
- XML modeling
- 研学旅游实践教育的开展助力文旅产业发展
- 显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
- ts 之 属性的修饰符public、private、protect
- ViewRootImpl和WindowManagerService笔记
- 树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
- Simple getting started example of Web Service
- bazel是否有学习的必要
猜你喜欢

EN 438-7建筑覆盖物装饰用层压板材产品—CE认证

PHP反序列化+MD5碰撞

研學旅遊實踐教育的開展助力文旅產業發展

Duchefa d5124 md5a medium Chinese and English instructions

Duchefa low melting point agarose PPC Chinese and English instructions

中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097

Analyze the knowledge transfer and sharing spirit of maker Education

Learning robots have no way to start? Let me show you the current hot research directions of robots

MySQL 千万数据量深分页优化, 拒绝线上故障!

【案例】元素的显示与隐藏的运用--元素遮罩
随机推荐
Duchefa p1001 plant agar Chinese and English instructions
研学旅游实践教育的开展助力文旅产业发展
Hdu2377bus pass (build more complex diagram +spfa)
最长摆动序列[贪心练习]
【案例】元素的显示与隐藏的运用--元素遮罩
概率论机器学习的先验知识(上)
Matplotlib drawing retouching (how to form high-quality drawings, such as how to set fonts, etc.)
Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
Deep merge object deep copy of vant source code parsing
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
Prior knowledge of machine learning in probability theory (Part 1)
PVC plastic sheets BS 476-6 determination of flame propagation properties
Careercup its 1.8 serial shift includes problems
ArcGIS\QGIS无插件加载(无偏移)MapBox高清影像图
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
100 cases of shell programming
请查收.NET MAUI 的最新学习资源
Simple getting started example of Web Service
当用户登录,经常会有实时的下拉框,例如,输入邮箱,将会@qq.com,@163.com,@sohu.com
Aitm 2-0003 horizontal combustion test