题: 给定长度为 2n 的数组, 你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从1 到 n 的 min(ai, bi) 总和最大。
法:给数组排序,然后取第0,2,4...2*(n-1)个位置的数即可
def arrayPairSum(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
nums.sort()
res=0
for i in range (0,len(nums),2):
res+=nums[i]
return res