Description:

Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.

显然,将排序后的数列的相邻两个数配对是最大的匹配方法。

class Solution {
public:int arrayPairSum(vector<int>& nums) {sort(nums.begin(), nums.end());int n = nums.size() / 2;int sum = 0;for (int i=0; i<n; i++) {sum += nums[i * 2];}return sum;}
};

leetcode#561 Array Partition I相关推荐

  1. [LeetCode]561. Array Partition I (数组分区 1)

    561. Array Partition I Given an array of 2n integers, your task is to group these integers into n pa ...

  2. LeetCode 561. Array Partition I

    题目: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say ...

  3. LeetCode 561 Array Partition I(数组划分)

    翻译 原文 Given an array of 2n integers, your task is to group these integers into n pairs of integer, s ...

  4. Leetcode PHP题解--D14 561. Array Partition I

    561. Array Partition I 题目链接 561. Array Partition I 题目分析 本题给了一个数组,要求将数组分为n个只有2个元素的一对. 使得每对数字中最小的数加起来的 ...

  5. Leetcode刷题记录[java]——561 Array Partition I

    一.前言 二.题561 Array Partition I Given an array of 2n integers, your task is to group these integers in ...

  6. 561.Array Partition I--Python

    刚开始学习Python编程,欢迎交流学习! 561.Array Partition I Given an array of 2n integers, your task is to group the ...

  7. 【刷leetcode,拿Offer-009】561. Array Partition I(贪心,C++)

    题目链接 Given an array of 2n integers, your task is to group these integers into n pairs of integer, sa ...

  8. 561. Array Partition I

    原题 Given an array of 2n integers, your task is to group these integers into n pairs of integer, say ...

  9. 561. 数组拆分 I(javascript)561. Array Partition I

    给定长度为 2n 的整数数组 nums ,你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), -, (an, bn) ,使得从 1 到 n 的 min(ai, bi) 总和 ...

最新文章

  1. Express中间件工作原理介绍
  2. RPA技术干货 | RPA防锁屏运行技巧
  3. scikit-learn点滴
  4. 找出第i个小元素(算法导论第三版9.2-4题)
  5. 【计算机网络】wireshark数据流追踪、图像抓取(转)
  6. 迷你世界无限迷你币体验服务器,迷你世界体验服无限迷你币
  7. 选择器、像素和百分比、颜色单位、文档流-css基础
  8. 7. 代码中特殊的注释技术——TODO、FIXME和XXX的用处
  9. JS 代码调试经验总结(菜鸟必读)
  10. cnchar.js 获取汉字的拼音和笔画数的js库 cnchar2.0 支持繁体字、笔画顺序、多音字词
  11. ecshop二次开发bug(一)
  12. Tracking 1.3 Online Trackers
  13. 【Unity3D实战】摇摆直升机开发实战(一)
  14. 5、提取snp indel 位点
  15. 贷款买房,利息怎么算?等额本金与等额本息
  16. U盘“请将磁盘插入U盘”,主控显示“chipYC2019”处理
  17. 计算机一级excel中模拟运算,2017年计算机一级《MS Office》操作试题及答案
  18. 使用FFMPEG工具包移除视频的水印
  19. SqlServer数据库常用sql语句
  20. element组件---其他组件

热门文章

  1. Keras 之 LSTM 有状态模型(stateful LSTM)和无状态模型(stateless LSTM)
  2. linux 移动某个文件夹及其所有子文件夹内指定类型的文件
  3. 有时候要跌到谷底,才会慢慢变好
  4. LabVIEW编程LabVIEW开发需要加班吗
  5. VB.net小技巧——读取文本文件并显示到文本框中
  6. 小白入门计算机视觉系列——ReID(一):什么是ReID?如何做ReID?ReID数据集?ReID评测指标?
  7. 想分享给马云和李开复的一篇文章
  8. linux移植嵌入式系统,嵌入式系统学习——S3C2451之Linux移植步骤
  9. void指针(void *的用法)
  10. ElementUI表单校验rules封装