当前位置:网站首页>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;
}
边栏推荐
- Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
- Exercise 7-2 finding the maximum value and its subscript (20 points)
- For programmers, if it hurts the most...
- El Table Radio select and hide the select all box
- 2021-08-11 function pointer
- 【Day1】 deep-learning-basics
- Intelligent gateway helps improve industrial data acquisition and utilization
- Kotlin: collection use
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
- Hands on deep learning (35) -- text preprocessing (NLP)
猜你喜欢
对于程序员来说,伤害力度最大的话。。。
Sort out the power node, Mr. Wang he's SSM integration steps
今日睡眠质量记录78分
ASP. Net to access directory files outside the project website
Intelligent gateway helps improve industrial data acquisition and utilization
基于线性函数近似的安全强化学习 Safe RL with Linear Function Approximation 翻译 1
智慧路灯杆水库区安全监测应用
Write a mobile date selector component by yourself
【OpenCV 例程200篇】218. 多行倾斜文字水印
Vs201 solution to failure to open source file HPP (or link library file)
随机推荐
The time difference between the past time and the present time of uniapp processing, such as just, a few minutes ago, a few hours ago, a few months ago
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 1
Write a mobile date selector component by yourself
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
View CSDN personal resource download details
Kotlin:集合使用
xxl-job惊艳的设计,怎能叫人不爱
Realsense of d435i, d435, d415, t265_ Matching and installation of viewer environment
How can people not love the amazing design of XXL job
AUTOSAR从入门到精通100讲(106)-域控制器中的SOA
Laravel文档阅读笔记-How to use @auth and @guest directives in Laravel
Log cannot be recorded after log4net is deployed to the server
Reasons and solutions for the 8-hour difference in mongodb data date display
Hands on deep learning (34) -- sequence model
Reprint: summation formula of proportional series and its derivation process
Qtreeview+ custom model implementation example
Sort out the power node, Mr. Wang he's SSM integration steps
Histogram equalization
ASP. Net to access directory files outside the project website
libmysqlclient. so. 20: cannot open shared object file: No such file or directory