数组-leetcode 561 Array Partition I
来源:互联网 发布:淘宝980ti能买吗 编辑:程序博客网 时间:2024/06/05 20:24
原题链接:Array Partition I
分析:这道题觉得没什么意思,关键是要明白所谓的pair的最小值的sum要最大,是不是让每个pair的min发挥的价值要大一点,换句话说就是我的最小值是不是要同时抹掉另一个很小的值,这样其他的pair的min就会大一点。这样一来,问题就迎刃而解了。排序,两两组队,取偶数位的sum就是结果。
代码如下:
class Solution {public: int arrayPairSum(vector<int>& nums) { /* Time Complexity:O(nlgn) Space Complexity:O(1) */ sort(nums.begin(),nums.end()); int res=0; auto beg=nums.begin(); auto end=nums.end(); while(beg!=end){ res+=*beg; beg+=2; } return res; }};
阅读全文
0 0
- 数组-leetcode 561 Array Partition I
- leetcode#561 Array Partition I
- leetcode-561-Array Partition I
- Leetcode 561: Array Partition I
- 【LeetCode】561 Array Partition I
- [leetcode 561]Array Partition I
- leetcode 561 Array Partition I
- leetcode.561 Array Partition I
- leetcode-561(Array Partition I)
- LeetCode-561 Array Partition I
- Leetcode 561 Array Partition I
- leetcode 561:Array Partition I
- LeetCode 561 Array Partition I
- Leetcode 561:Array Partition I
- Leetcode 561 Array Partition I
- LeetCode[561]Array Partition I
- leetcode 561 Array Partition I
- LeetCode.561 Array Partition I
- 二叉树的遍历-层次遍历
- WHAT IS SDN?
- PHP设计模式----单例模式(singleton)
- mybatis 条件判断的一些字符
- maven web 工程生成war包
- 数组-leetcode 561 Array Partition I
- LitePal通过adb shell查看表中字段命令
- idea 工具热布署方案汇总
- Java环境变量配置
- 设计模式(六)bridge
- HTTP中GET请求和POST请求的区别
- http线程并发测试-化无为有的漏洞挖掘 jmter
- python脚本输入密码判断
- paypal在线支付演示下载PHP版