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