当前位置:网站首页>力扣 729. 我的日程安排表 I
力扣 729. 我的日程安排表 I
2022-07-05 19:18: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 。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/my-calendar-i
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
方法1:模拟

Java实现
class MyCalendar {
List<int[]> list;
public MyCalendar() {
list = new ArrayList<>();
}
public boolean book(int start, int end) {
end--; //
for (int[] var : list) {
int l = var[0], r = var[1];
if (start > r || end < l) continue;
return false;
}
list.add(new int[]{
start, end});
return true;
}
}

边栏推荐
- 不愧是大佬,字节大牛耗时八个月又一力作
- 决策树与随机森林
- redis集群模拟消息队列
- Common interview questions in Android, 2022 golden nine silver ten Android factory interview questions hit
- Debezium系列之:postgresql从偏移量加载正确的最后一次提交 LSN
- Fundamentals of shell programming (Part 8: branch statements -case in)
- PHP uses ueditor to upload pictures and add watermarks
- 测试外包公司怎么样?
- Go语言 | 03 数组、指针、切片用法
- Golang through pointer for Range implements the change of the value of the element in the slice
猜你喜欢

Technology sharing | common interface protocol analysis

Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法

通过POI追加数据到excel中小案例

Technology sharing | interface testing value and system

Benefits of automated testing

测试的核心价值到底是什么?

块编辑器如何选择?印象笔记 Verse、Notion、FlowUs

微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知

Android面试,android音视频开发

Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
随机推荐
软件测试工程师是做什么的?待遇前景怎么样?
golang通过指针for...range实现切片中元素的值的更改
5年经验Android程序员面试27天,2022程序员进阶宝典
JAD installation, configuration and integration idea
What do software test engineers do? How about the prospect of treatment?
Ten years at sea: old and new relay, dark horse rising
C# 语言的高级应用
通过POI追加数据到excel中小案例
Go语言 | 02 for循环及常用函数的使用
Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
如何在2022年更明智地应用智能合约?
redis集群模拟消息队列
HAC cluster modifying administrator user password
强化学习-学习笔记4 | Actor-Critic
After the company went bankrupt, the blackstones came
手机开户选择哪家券商公司比较好哪家平台更安全
机器学习基础(三)——KNN/朴素贝叶斯/交叉验证/网格搜索
Is it safe for China Galaxy Securities to open an account? Securities account opening
Common interview questions in Android, 2022 golden nine silver ten Android factory interview questions hit
[performance test] jmeter+grafana+influxdb deployment practice