# 1229. Meeting Scheduler ###### tags: `Leetcode` `Medium` `Two Pointers` Link: https://leetcode.com/problems/meeting-scheduler/ ## 思路 $O(NlogN)$ $O(1)$ 先根据```arr[0]```排序 然后双指针 注意while的条件 有的时候只要有一个小于length就可以继续跑下去 ## Code ```java= class Solution { public List<Integer> minAvailableDuration(int[][] slots1, int[][] slots2, int duration) { Arrays.sort(slots1, (a,b)->(a[0]-b[0])); Arrays.sort(slots2, (a,b)->(a[0]-b[0])); int p1=0, p2=0; List<Integer> ans = new ArrayList<>(); while(p1<slots1.length && p2<slots2.length){ int[] intersect = new int[]{Math.max(slots1[p1][0], slots2[p2][0]), Math.min(slots1[p1][1],slots2[p2][1])}; if(intersect[0]<intersect[1] && intersect[1]-intersect[0]>=duration){ ans.add(intersect[0]); ans.add(intersect[0]+duration); return ans; } if(slots1[p1][1]>slots2[p2][1]){ p2++; } else{ p1++; } } return ans; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up