leetcode 561. Array Partition I
Question
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
|
|
Tip
输入一个数组,对数组中元素进行两两分组,使得每一组最小值相加得到的结果尽可能大,最后给出最大值。
解题思路是现将数组进行排序,再进行两两组合的结果便是最优解
Code
|
|