当前位置:网站首页>力扣 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;
}
}
边栏推荐
- 不愧是大佬,字节大牛耗时八个月又一力作
- Mathematical modeling of oil pipeline layout MATLAB, mathematical model of oil pipeline layout
- 1亿单身男女撑起一个IPO,估值130亿
- 什么是面上项目
- acm入门day1
- Hiengine: comparable to the local cloud native memory database engine
- Can Leica capture the high-end market offered by Huawei for Xiaomi 12s?
- R language Visual scatter plot graph, add labels to some data points in the graph, and always display all labels, even if they have too much overlap. Ggrep package helps
- Tupu software digital twin | visual management system based on BIM Technology
- 数学分析_笔记_第9章:曲线积分与曲面积分
猜你喜欢
大厂面试必备技能,2022Android不死我不倒
Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
C# 语言的基本语法结构
决策树与随机森林
Go语言 | 02 for循环及常用函数的使用
acm入门day1
JAD installation, configuration and integration idea
Go语言 | 01 WSL+VSCode环境搭建避坑指南
块编辑器如何选择?印象笔记 Verse、Notion、FlowUs
Mariadb root用户及普通用户的密码 重置
随机推荐
太牛了,看这篇足矣了
[AI framework basic technology] automatic derivation mechanism (autograd)
Decision tree and random forest
CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]
【AI 框架基础技术】自动求导机制 (Autograd)
集合
Hiengine: comparable to the local cloud native memory database engine
Fuzor 2020软件安装包下载及安装教程
Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
MMO project learning 1: preheating
潘多拉 IOT 开发板学习(HAL 库)—— 实验8 定时器中断实验(学习笔记)
Postman核心功能解析-参数化和测试报告
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
Android interview, Android audio and video development
Information / data
决策树与随机森林
How to quickly advance automated testing? Listen to the personal feelings of the three bat test engineers
出海十年:新旧接力,黑马崛起
golang通过指针for...range实现切片中元素的值的更改
Advanced application of C # language