翻译

原文

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.

Example 1:
Input: [1,4,3,2]

Output: 4
Explanation: n is 2, and the maximum sum of pairs is 4.
Note:
n is a positive integer, which is in the range of [1, 10000].
All the integers in the array will be in the range of [-10000, 10000].

代码

 public int arrayPairSum(int[] nums) {Arrays.sort(nums);int sum = 0;for (int i = 0; i < nums.length; i+=2) {sum += nums[i];}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

    Description: Given an array of 2n integers, your task is to group these integers into n pairs of int ...

  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. 561. 数组拆分 I(javascript)561. Array Partition I

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

  8. 【刷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 ...

  9. 561. Array Partition I

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

最新文章

  1. C/MFC如何获得应用程序当前路径(整理)
  2. 程序员有趣的面试智力题(转)
  3. 微信小程序长按保存图片
  4. python 变量
  5. 后“量子霸权”时代你不可错过的几本好书
  6. mt4双线macd_手机版MT4怎样添加双线MACD指标 手机MT4双线MACD设置方法
  7. 解决ssh登录Host key verification failed
  8. 一个都不能少:全面认识IE插件
  9. itools 苹果录屏大师 java_AirPlayer电脑版(itools苹果录屏大师)下载|AirPlayer电脑免费版...
  10. 谷歌浏览器为什么不能自定义安装路径?
  11. 编写业务逻辑代码-清晰可维护是很重要的
  12. 【UI】优秀的网站欣赏以及分析
  13. rsa签名算法c语言,数字签名算法rsa
  14. CMP SUB 区别
  15. 8K播放网络全终端播放器H5播放器网页直播/点播播放器EasyPlayer和vlc播放RTSP流地址不兼容问题排查解决
  16. 关于No enclosing instance of type MyProject is accessible的报错
  17. 父组件给孙子组件传值
  18. 使用jol查看对象内部布局
  19. echarts map (echarts地图)使用总结
  20. armbian n1 桌面_N1盒子初体验(降级+刷armbian)

热门文章

  1. java nio socket
  2. 【LeetCode】正则表达式匹配
  3. linux查看cp2102,微雪电子CP2102(type A)USB转USART简介
  4. 关于SN74HC14PW
  5. 计算机网络:数据链路层之虚拟局域网,高速以太网
  6. Blender齿轮制作
  7. 牡牛和牝牛(信息学奥赛一本通 1652)
  8. java lambdamart库,LambdaMART笔记
  9. 经销商转型为什么要选择移动订货平台?
  10. mysql唯一索引的关键字_mysql中唯一索引的关键字是什么