#### 题目

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.

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].


#### 思路一代码

    int arrayPairSum(vector<int>& nums) {
if (nums.size() == 2) {
return nums[0] < nums[1] ? nums[0] : nums[1];
}
std::sort(nums.begin(), nums.end());
int sum = 0;
for (int i = 0; i < nums.size(); i += 2) {
sum += nums[i];
}
return sum;
}


#### 思路二代码

    int arrayPairSumBucketSort(vector<int>& nums) {
vector<int> bucket(10000 * 2 + 1, 0);
int lower = 10000 * 2;
for (int i = 0; i < nums.size(); ++i) {
bucket[nums[i] + 10000] += 1;
if (nums[i] + 10000 < lower) {
lower = nums[i] + 10000;
}
}

int count = 0;
int sum = 0;
bool skip = false;
while (count < nums.size() / 2) {
if (bucket[lower] > 0 && !skip) {
sum += lower - 10000;
skip = true;
++count;
bucket[lower]--;
} else if (bucket[lower] > 0 && skip) {
skip = false;
bucket[lower]--;
} else {
++lower;
}
}
return sum;
}