当前位置:网站首页>力扣 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;
}
}
边栏推荐
- How MySQL queries and modifies JSON data
- Technology sharing | interface testing value and system
- Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
- What do software test engineers do? How about the prospect of treatment?
- MMO项目学习一:预热
- C# 语言的高级应用
- flume系列之:拦截器过滤数据
- Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
- Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
- 如何实现游戏中的在线计时器和离线计时器
猜你喜欢
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
Common interview questions in Android, 2022 golden nine silver ten Android factory interview questions hit
Common - Hero Minesweeper
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]
太牛了,看这篇足矣了
安卓面试宝典,2022Android面试笔试总结
不愧是大佬,字节大牛耗时八个月又一力作
Tupu software digital twin | visual management system based on BIM Technology
开源 SPL 消灭数以万计的数据库中间表
随机推荐
完爆面试官,一线互联网企业高级Android工程师面试题大全
Mathematical modeling of oil pipeline layout MATLAB, mathematical model of oil pipeline layout
安卓面试宝典,2022Android面试笔试总结
Go语言 | 01 WSL+VSCode环境搭建避坑指南
redis集群模拟消息队列
MySql中的longtext字段的返回问题及解决
Applet modification style (placeholder, checkbox style)
IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
JAD installation, configuration and integration idea
MMO項目學習一:預熱
Fundamentals of shell programming (Chapter 9: loop)
Summer Challenge database Xueba notes, quick review of exams / interviews~
关于 Notion-Like 工具的反思和畅想
Go语言 | 02 for循环及常用函数的使用
Apprentissage du projet MMO I: préchauffage
Which securities company is better and which platform is safer for mobile account opening
The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application