1877.数组中最大数对和的最小值
链接:1877.数组中最大数对和的最小值
难度:Medium
标签:贪心、数组、双指针、排序
简介:请你在最优数对划分的方案下,返回最小的 最大数对和 。
题解 1 - typescript
- 编辑时间:2021-07-20
- 执行用时:332ms
- 内存消耗:53.2MB
- 编程语言:typescript
- 解法介绍:贪心,排序后收尾相加。
function minPairSum(nums: number[]): number {
const n = nums.length;
const arr = new Array(n / 2).fill(0);
nums.sort((a, b) => a - b);
for (let i = 0; i < n / 2; i++) arr[i] = nums[i] + nums[n - 1 - i];
return Math.max(...arr);
}