1877. Minimize Maximum Pair Sum in Array
Last updated
Last updated
class Solution {
public int minPairSum(int[] nums) {
Arrays.sort(nums);
int res = Integer.MIN_VALUE;
int left = 0;
int right = nums.length - 1;
while (left < right) {
res = Math.max(res, nums[left] + nums[right]);
left++;
right--;
}
return res;
}
}
/*
[3,5,2,3]
2 3 3 5 => sort
5 8
6 7
[3,5,4,2,4,6]
2 3 4 4 5 6 => sort
2 6
3 5
4 4
*/