当前位置:网站首页>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;
}
边栏推荐
- Application of safety monitoring in zhizhilu Denggan reservoir area
- xxl-job惊艳的设计,怎能叫人不爱
- Mmclassification annotation file generation
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- Does any teacher know how to inherit richsourcefunction custom reading Mysql to do increment?
- 用数据告诉你高考最难的省份是哪里!
- libmysqlclient. so. 20: cannot open shared object file: No such file or directory
- Golang 类型比较
- Summary of reasons for web side automation test failure
- Exercise 9-4 finding books (20 points)
猜你喜欢
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 1
Tables in the thesis of latex learning
Summary of reasons for web side automation test failure
C # use ffmpeg for audio transcoding
What are the advantages of automation?
Machine learning -- neural network (IV): BP neural network
Qtreeview+ custom model implementation example
Safety reinforcement learning based on linear function approximation safe RL with linear function approximation translation 2
【Day1】 deep-learning-basics
Pcl:: fromrosmsg alarm failed to find match for field 'intensity'
随机推荐
【Day2】 convolutional-neural-networks
【Day2】 convolutional-neural-networks
Kotlin:集合使用
Qtreeview+ custom model implementation example
Kubernetes CNI 插件之Fabric
Dos:disk operating system, including core startup program and command program
Latex learning insertion number - list of filled dots, bars, numbers
品牌连锁店5G/4G无线组网方案
uniapp---初步使用websocket(长链接实现)
leetcode1-3
C # use smtpclient The sendasync method fails to send mail, and always returns canceled
Exercise 9-5 address book sorting (20 points)
Modules golang
Hands on deep learning (43) -- machine translation and its data construction
uniapp 小于1000 按原数字显示 超过1000 数字换算成10w+ 1.3k+ 显示
Exercise 9-1 time conversion (15 points)
How can people not love the amazing design of XXL job
Today's sleep quality record 78 points
Write a mobile date selector component by yourself
Pcl:: fromrosmsg alarm failed to find match for field 'intensity'