首页 > 其他分享 >1877.minimize-maximum-pair-sum-in-array 数组中最大数对和的最小值

1877.minimize-maximum-pair-sum-in-array 数组中最大数对和的最小值

时间:2023-02-02 14:46:45浏览次数:56  
标签:最大数 nums minimize res sum int 1877 配对

问题描述

1877.数组中最大数对和的最小值

解题思路

贪心

将数组从小到大排序,最小最大配对,次小次大配对,依次配对,结果就是这些配对和的最大值。

代码

class Solution {
public:
    int minPairSum(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int res = 0;
        for (int i = 0; i < nums.size(); i++) {
            res = max(res, nums[i] + nums[nums.size() - 1 -i]);
        }
        return res;
    }
};

标签:最大数,nums,minimize,res,sum,int,1877,配对
From: https://www.cnblogs.com/zwyyy456/p/17085937.html

相关文章

  • Consecutive sum II 1977
    ​​点击这里看题目链接ConsecutivesumII​​#include<stdio.h>#include<math.h>intmain(){unsignedlonglongm,n;scanf("%I64d",&n);while(n--){scan......
  • NYOJ-448-寻找最大数
    寻找最大数1000 ms | 内存限制:655352请在整数n中删除m个数字,使得余下的数字按原次序组成的新数最大,比如当n=92081346718538,m=10时,则新的最大数是988......
  • Atcoder ABC282H Min + Sum
    https://atcoder.jp/contests/abc282/tasks/abc282_h挂了好久发现二分写挂了……对于\(\min\{a_i\}\)这一部分,不难想到找到当前\(\min\{a_i\}\)的位置计算其左右两......
  • jmeter generate report使用 failed with message:Consumer failed with message:Begi
     原因:電腦安裝java版本不兼容導致解決方法:-UseJDK<17-UseJMeternightlybuildwhichcontainsthefixhttps://ci.apache.org/projects/jmeter/nightlies/......
  • 23/1/29-LeetCode 15: 3Sum
    LeetCode15:3Sum写过了2sum,现在再来写3sum,虽然大一下数据结构是写过的orz,应该是写过的,但是某人忘得很彻底。。。没事不迟!0.回顾一下2sum在一维array数组里找到两个数......
  • c# 提取注释即summary
    1、需要在项目属性中开启生成xml启动项2、添加辅助类XmlCommentHelper///<summary>///注释辅助类///</summary>publicclassXmlCommentHelper......
  • Sum of Squares Theorems
    这个在Cryptography里有用,因为对于大的数找起来很难Legendre'sthreesquaretheorem: apositiveinteger canbeexpressedasasumof4squaresifandonlyifit......
  • My technical summary in 2022
    IntroIt'squitetoughformein2022.Iwentthroughchangingjob,injuryandcovidepidemic.AboutTechnology,IlearnedcudaandGPUprogrammingatthebeg......
  • vue2+SummerNote
    简介:想给加一个富文本编辑器到页面上,选择了summernote。接下来开始把summernote往vue这个框架里塞,死活塞不进去。最后把vue3回退到vue2,世界清净了。大致过程:下载相关包,引......
  • 2-sum 和 3-sum 问题的快速解法
    用科学方法分析程序中介绍了3-sum问题的暴力解法(ThreeSum)——用三个嵌套的for循环来求和为0的三元组个数,增长数量级为立方级别。类似地,对于2-sum问题(找出一个输入......