一、前言

二、题561 Array Partition I

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: 4Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).

Note:

  1. n is a positive integer, which is in the range of [1, 10000].
  2. All the integers in the array will be in the range of [-10000, 10000].

三、解题思路

 1 class Solution {
 2     public int arrayPairSum(int[] nums) {
 3         Arrays.sort(nums);
 4         int result = 0;
 5         for (int i = 0; i < nums.length; i += 2) {
 6             result += nums[i];
 7         }
 8         return result;
 9     }
10 }

转载于:https://www.cnblogs.com/Myoungs/p/7832870.html

Leetcode刷题记录[java]——561 Array Partition I相关推荐

  1. 算法记录 牛客网 leetcode刷题记录

    算法记录 & 牛客网 & leetcode刷题记录 解题思路 STL容器 常用算法模板 堆排序 插入排序 快速排序 BFS层序遍历 二叉树 JZ55 二叉树的深度 BST(binary ...

  2. LeetCode刷题记录12——232. Implement Queue using Stacks(easy)

    LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...

  3. LeetCode刷题记录11——290. Word Pattern(easy)

    LeetCode刷题记录11--290. Word Pattern(easy) 目录 LeetCode刷题记录11--290. Word Pattern(easy) 题目 语言 思路 源码 后记 题目 ...

  4. LeetCode刷题记录10——434. Number of Segments in a String(easy)

    LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...

  5. LeetCode刷题记录9——58. Length of Last Word(easy)

    LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...

  6. LeetCode刷题记录8——605. Can Place Flowers(easy)

    LeetCode刷题记录8--605. Can Place Flowers(easy) 目录 LeetCode刷题记录8--605. Can Place Flowers(easy) 题目 语言 思路 ...

  7. LeetCode刷题记录7——824. Goat Latin(easy)

    LeetCode刷题记录7--824. Goat Latin(easy) 目录 LeetCode刷题记录7--824. Goat Latin(easy) 题目 语言 思路 后记 题目 题目需要将一个输 ...

  8. LeetCode刷题记录6——696. Count Binary Substrings(easy)

    LeetCode刷题记录6--696. Count Binary Substrings(easy) 目录 LeetCode刷题记录6--696. Count Binary Substrings(eas ...

  9. LeetCode刷题记录5——441. Arranging Coins(easy)

    LeetCode刷题记录5--441. Arranging Coins(easy) 目录 LeetCode刷题记录5--441. Arranging Coins(easy) 题目 语言 思路 后记 题 ...

最新文章

  1. 1月书讯 | 开年多本重点书
  2. 01----mockjs介绍
  3. HTMLCollection元素的For循环
  4. 半潜式深海平台动力定位控制技术研究
  5. bzoj2326 [HNOI2011]数学作业
  6. 升序排列python_Python3基础 sort 将一个列表中的值升序排列
  7. java utils
  8. SAP Spartacus 基于行项目的订单取消功能(order cancel)实现
  9. 【NBIoT无线模块DTU数传电台】串口服务器RS232/RS485端口工业路由信号传输
  10. NagiosQL 3的安装
  11. 中缀表达式 转成 后缀表达式
  12. android怎么备份镜像文件,如何备份手机系统镜像? - Android系统区 - 无忧启动论坛 - Powered by Discuz!...
  13. js前置递增和后置递增
  14. 循序渐进学SAP系列(一):--SAP该如何入门
  15. 苹果手机用什么蓝牙耳机好?适合苹果的音乐蓝牙耳机推荐
  16. 【成神之路】开放设计编程相关面试题
  17. 数据库DevOps:我们如何提供安全、稳定、高效的研发全自助数据库服务-iDB/DMS企业版...
  18. color demura原理_AMOLED中的补偿技术之外部光学补偿(Demura)
  19. 5款提高办公效率的好软件,最后一个绝了
  20. 多家自媒体平台实现内容互通:自媒体平台的圈地运动

热门文章

  1. 对大文件进行只打印过滤条件到列表元素(优化)
  2. Atcoder 077E - guruguru(线段树+dp)
  3. UVA5876 Writings on the Wall 扩展KMP
  4. 穷小子做网站赚钱终得丈母娘认可
  5. DataGridView实现多维表头
  6. 父窗体中弹出新窗体,然后获取弹出窗体的返回值。
  7. (34)System Verilog引用包中定义的类(失败)
  8. (26)System Verilog范围随机函数约束类内变量
  9. (65)Verilog HDL多模块重复例化:generate for
  10. SDL环境初始化测试代码