标签:span blog des 数位 exp turn output 数字 air
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 = min(1, 2) + min(3, 4).
Note:
Java Solution:
Runtime beats 83.27%
完成日期:05/10/2017
关键词:Array
关键点:Sort
1 public class Solution 2 { 3 public int arrayPairSum(int[] nums) 4 { 5 int sum = 0; 6 7 Arrays.sort(nums); 8 9 for(int i=0; i<nums.length; i+=2) 10 sum += nums[i]; 11 12 return sum; 13 } 14 }
参考资料:N/A
LeetCode 561. Array Partition I (数组分隔之一)
标签:span blog des 数位 exp turn output 数字 air
原文地址:http://www.cnblogs.com/jimmycheng/p/7119306.html