当前位置:网站首页>leetcode1229. Schedule the meeting
leetcode1229. Schedule the meeting
2022-07-04 10:16:00 【JoesonChan】
subject
You are an administrative assistant , I have two customers' free schedules :slots1 and slots2, And the expected duration of the meeting duration, Please arrange a suitable meeting time for them .
「 Meeting time 」 Yes, both customers are free to attend , And the duration can meet the expected time duration Of The earliest time interval .
If there is no meeting time to meet the requirements , Please return one An empty array .
「 free time 」 The format is [start, end], From start time start And end time end form , From start Start , To end end .
Ensure that the data is valid : The same person's free time will not overlap , in other words , For two free times of the same person [start1, end1] and [start2, end2], or start1 > end2, or start2 > end1.
Example 1:
Input :slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8
Output :[60,68]
Example 2:
Input :slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 12
Output :[]
Tips :
1 <= slots1.length, slots2.length <= 10^4
slots1[i].length, slots2[i].length == 2
slots1[i][0] < slots1[i][1]
slots2[i][0] < slots2[i][1]
0 <= slots1[i][j], slots2[i][j] <= 10^9
1 <= duration <= 10^6
Realization
public static int[] free(int[][] nums1, int[][] nums2, int duration) {
int index1 = 0;
int index2 = 0;
int[] result = new int[2];
while (index1 < nums1.length && index2 < nums2.length) {
int begin = Math.max(nums1[index1][0], nums2[index2][0]);
int end = Math.min(nums1[index1][1], nums2[index2][1]);
if (end - begin >= duration) {
result[0] = begin;
result[1] = begin + duration;
return result;
} else if (nums2[index2][1] > nums1[index1][1]) {
index1++;
} else {
index2++;
}
}
return result;
}
边栏推荐
- C # use gdi+ to add text with center rotation (arbitrary angle)
- How can people not love the amazing design of XXL job
- Doris / Clickhouse / Hudi, a phased summary in June
- 2020-03-28
- Lavel document reading notes -how to use @auth and @guest directives in lavel
- JDBC and MySQL database
- 什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
- How do microservices aggregate API documents? This wave of show~
- Realsense d435 d435i d415 depth camera obtains RGB map, left and right infrared camera map, depth map and IMU data under ROS
- Write a mobile date selector component by yourself
猜你喜欢
Normal vector point cloud rotation
Hands on deep learning (37) -- cyclic neural network
PHP代码审计3—系统重装漏洞
Regular expression (I)
Use the data to tell you where is the most difficult province for the college entrance examination!
MongoDB数据日期显示相差8小时 原因和解决方案
入职中国平安三周年的一些总结
百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
【OpenCV 例程200篇】218. 多行倾斜文字水印
Reasons and solutions for the 8-hour difference in mongodb data date display
随机推荐
Ruby time format conversion strftime MS matching format
Machine learning -- neural network (IV): BP neural network
Mmclassification annotation file generation
Exercise 9-4 finding books (20 points)
Modules golang
In the case of easyUI DataGrid paging, click the small triangle icon in the header to reorder all the data in the database
入职中国平安三周年的一些总结
Doris / Clickhouse / Hudi, a phased summary in June
Golang Modules
Work order management system OTRs
Whether a person is reliable or not, closed loop is very important
How can Huawei online match improve the success rate of player matching
技术管理进阶——如何设计并跟进不同层级同学的绩效
Ruby时间格式转换strftime毫秒匹配格式
Basic principle of servlet and application of common API methods
直方图均衡化
AUTOSAR from getting started to mastering 100 lectures (106) - SOA in domain controllers
IIS configure FTP website
华为联机对战如何提升玩家匹配成功几率
Exercise 8-7 string sorting (20 points)