每日一题力扣561

给定长度为 2n 的整数数组 nums ,你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从 1 到 n 的 min(ai, bi) 总和最大。

返回该 最大总和 。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/array-partition-i
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

class Solution:
    def arrayPairSum(self, nums: List[int]) -> int:
        nums=sorted(nums)
        count=0
        for i in range(0,len(nums),2):#每次走两个步长
            count+=nums[i]
        return count
原文地址:https://www.cnblogs.com/liuxiangyan/p/14602788.html