当前位置:网站首页>【日常训练】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;
}
}
边栏推荐
- Aitm2-0002 12s or 60s vertical combustion test
- PHP反序列化+MD5碰撞
- 水泥胶黏剂BS 476-4 不燃性测试
- Web Service简单入门示例
- haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
- Introduction to TS, constructor and its this, inheritance, abstract class and interface
- 示波器探头对信号源阻抗的影响
- wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
- leetcode:1755. 最接近目标值的子序列和
- The development of research tourism practical education helps the development of cultural tourism industry
猜你喜欢

显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??

学习机器人无从下手?带你体会当下机器人热门研究方向有哪些

教你自己训练的pytorch模型转caffe(三)

Using webassembly to operate excel on the browser side

LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line

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

基于vertx-web-sstore-redis的改造实现vertx http应用的分布式session

PHP反序列化+MD5碰撞

Norgen AAV extractant box instructions (including features)

haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
随机推荐
sql系列(基础)-第二章 限制和排序数据
CLion配置visual studio(msvc)和JOM多核编译
Cutting edge technology for cultivating robot education creativity
当用户登录,经常会有实时的下拉框,例如,输入邮箱,将会@qq.com,@163.com,@sohu.com
bazel是否有学习的必要
Écrire une interface basée sur flask
phpstudy小皮的mysql点击启动后迅速闪退,已解决
Influence of oscilloscope probe on measurement bandwidth
Implementation of redis unique ID generator
水泥胶黏剂BS 476-4 不燃性测试
研学旅游实践教育的开展助力文旅产业发展
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
XML modeling
珍爱网微服务底层框架演进从开源组件封装到自研
ts 之 属性的修饰符public、private、protect
Monorepo management methodology and dependency security
[case] Application of positioning - Taobao rotation map
Maker education infiltrating the transformation of maker spirit and culture
Interpreting the daily application functions of cooperative robots
hdu2377Bus Pass(构建更复杂的图+spfa)