当前位置:网站首页>【日常训练】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;
}
}
边栏推荐
- Abnova CD81 monoclonal antibody related parameters and Applications
- 五层网络协议
- vant 源码解析之 utils/index.ts 工具函数
- matplotlib绘图润色(如何形成高质量的图,例如设如何置字体等)
- PHP反序列化+MD5碰撞
- 基於flask寫一個接口
- MySQL fully parses json/ arrays
- Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
- Chemical properties and application instructions of prosci Lag3 antibody
- Aitm 2-0003 horizontal combustion test
猜你喜欢

Duchefa d5124 md5a medium Chinese and English instructions

Display DIN 4102-1 Class B1 fire test requirements

珍爱网微服务底层框架演进从开源组件封装到自研

Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel

浅聊我和一些编程语言的缘分

Talk about my fate with some programming languages

Prosci LAG-3 recombinant protein specification

Which is the best online collaboration product? Microsoft loop, notion, flowus

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

Influence of oscilloscope probe on measurement bandwidth
随机推荐
PHP deserialization +md5 collision
Is it necessary for bazel to learn
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
Monorepo management methodology and dependency security
ViewRootImpl和WindowManagerService笔记
Influence of oscilloscope probe on measurement bandwidth
wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
判断横竖屏的最佳实现
Influence of oscilloscope probe on signal source impedance
Prior knowledge of machine learning in probability theory (Part 1)
模式-“里氏替换原则”
驱动壳美国测试UL 2043 符合要求有哪些?
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
教你自己训练的pytorch模型转caffe(二)
[case] Application of positioning - Taobao rotation map
Sequence alignment
ts 之 属性的修饰符public、private、protect
10000+ 代码库、3000+ 研发人员大型保险集团的研发效能提升实践
poj 3414 Pots (bfs+线索)
Enclosed please find. Net Maui's latest learning resources