Skip to content

Latest commit

 

History

History
47 lines (30 loc) · 1.25 KB

561-array-partition-i.md

File metadata and controls

47 lines (30 loc) · 1.25 KB

561. Array Partition I - 数组拆分 I

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

示例 1:

输入: [1,4,3,2]

输出: 4
解释: n 等于 2, 最大总和为 4 = min(1, 2) + min(3, 4).

提示:

  1. n 是正整数,范围在 [1, 10000].
  2. 数组中的元素范围在 [-10000, 10000].

题目标签:Array

题目链接:LeetCode / LeetCode中国

题解

Language Runtime Memory
python3 192 ms N/A
class Solution:
    def arrayPairSum(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        return sum(sorted(nums)[::2])