561. Array Partition I
来源:互联网 发布:如何将照片导入mac 编辑:程序博客网 时间:2024/05/21 00:53
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:
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 class Solution { 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; }}
阅读全文
0 0
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 第二天:勇于踏出去
- Poj 1502 MPI Maelstrom (Dijkstra
- node.js 探索之路(概念进阶)
- Android 完整漂亮问卷、试卷 -- 支持单选、判断、不定项
- 二叉树的存储和遍历
- 561. Array Partition I
- 娜娜梦游仙境系列——多民族王国
- 图论--最小生成树总结(Prim&&Kruskal)
- 转 Java-Swing嵌入浏览器(一) 今天要说的额是浏览器的第一个版本是用DJnative-swt和swt包开发的调用本地浏览器和webkit浏览器的示例 这是我的工程目录【源码见最后】: i
- find查找文件忽略某些目录
- 算法学习笔记--2. Selection sort & Fibonacci sequence
- before和:after
- Java NIO(一)
- 我想成为一只特立独行的猪