Advantage Shuffle LeetCode solution in Java

1
class Solution {
2
public int[] advantageCount(int[] nums1, int[] nums2) {
3
Arrays.sort(nums1);
4
PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> (b[0] - a[0]));
5
for (int i = 0; i < nums2.length; i++) pq.add(new int[] {nums2[i], i});
6
int left = 0, right = nums1.length - 1;
7
while (left <= right) {
8
int[] get = pq.poll();
9
int pos = get[1], max = get[0];
10
if (nums1[right] > max) {
11
nums2[pos] = nums1[right];
12
right--;
13
} else {
14
nums2[pos] = nums1[left];
15
left++;
16
}
17
}
18
return nums2;
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0