当前位置:网站首页>Force buckle 729 My schedule I
Force buckle 729 My schedule I
2022-07-05 19:28:00 【Ruthless young Fisherman】
subject
Achieve one MyCalendar Class to store your schedule . If the schedule to be added does not cause Repeat Booking , You can store this new schedule .
When there is some time overlap between the two schedules ( For example, both schedules are in the same time ), It will produce Repeat Booking .
The schedule can use a pair of integers start and end Express , The time here is a half open interval , namely [start, end), The set of real Numbers x For the range of , start <= x < end .
Realization MyCalendar class :
MyCalendar() Initialize calendar object .
boolean book(int start, int end) If the schedule can be successfully added to the calendar without causing duplicate bookings , return true . otherwise , return false And don't add the schedule to the calendar .
Example
Input :
[“MyCalendar”, “book”, “book”, “book”]
[[], [10, 20], [15, 25], [20, 30]]
Output :
[null, true, false, true]
explain :
MyCalendar myCalendar = new MyCalendar();
myCalendar.book(10, 20); // return True
myCalendar.book(15, 25); // return False , This schedule cannot be added to the calendar , Because of time 15 Has been booked by another schedule .
myCalendar.book(20, 30); // return True , This schedule can be added to the calendar , Because the first schedule is booked at less than each time 20 , And does not include time 20 .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/my-calendar-i
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Method 1: simulation

Java Realization
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;
}
}

边栏推荐
- Worthy of being a boss, byte Daniel spent eight months on another masterpiece
- How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
- Go语言 | 02 for循环及常用函数的使用
- shell编程基础(第9篇:循环)
- The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
- HAC cluster modifying administrator user password
- IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
- 建议收藏,我的腾讯Android面试经历分享
- MMO project learning 1: preheating
- HiEngine:可媲美本地的云原生内存数据库引擎
猜你喜欢

Common - Hero Minesweeper
![[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform](/img/64/08faef0fccec93337f0716ac57dd8e.jpg)
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform

That's awesome. It's enough to read this article
The problem of returning the longtext field in MySQL and its solution

The basic grammatical structure of C language

C# 语言的高级应用

How to convert word into PDF? Word to PDF simple way to share!

5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic

Reflection and imagination on the notation like tool

Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
随机推荐
Password reset of MariaDB root user and ordinary user
C# 语言的基本语法结构
JAD installation, configuration and integration idea
Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
Common - Hero Minesweeper
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]
cf:B. Almost Ternary Matrix【對稱 + 找規律 + 構造 + 我是構造垃圾】
What do software test engineers do? How about the prospect of treatment?
Apprentissage du projet MMO I: préchauffage
Django使用mysqlclient服务连接并写入数据库的操作过程
Django uses mysqlclient service to connect and write to the database
How to convert word into PDF? Word to PDF simple way to share!
Cf:b. almost Terry matrix [symmetry + finding rules + structure + I am structural garbage]
Android面试,android音视频开发
MMO项目学习一:预热
测试的核心价值到底是什么?
Reflection and imagination on the notation like tool
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception