LeetCode-561. Array Partition I-排序
2017-11-06 00:31
393 查看
题目:
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 1:
Input: [1,4,3,2] Output: 4 Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
答案:
class Solution(object): def arrayPairSum(self, nums): """ :type nums: List[int] :rtype: int """ nums.sort() return sum(nums[::2])
知识点:
1.排序
八大排序算法的 Python 实现2.列表
Python 列表(List)相关文章推荐
- leetcode 561. Array Partition I 数组元素分组的最小值的和的最大值+直接排序即可
- 【Leetcode】561. Array Partition I(数组分割一)
- leetcode 561. Array Partition I(C语言)10
- Leetcode 561. Array Partition I(Easy)
- LeetCode——561. Array Partition I(贪心,C++)
- LeetCode 561. Array Partition I (排序、遍历)
- leetcode_561. Array Partition I ? 待解决
- LeetCode 561. Array Partition I
- LeetCode | 561. Array Partition I 数学归纳法题
- [LeetCode]561. Array Partition I (数组分区 1)
- leetcode -- 561. Array Partition I 【贪心算法 + 正确性证明】
- [Leetcode] 561. Array Partition I 解题报告
- Leetcode 561 Array Partition I
- LeetCode Partition List
- 【leetcode】 Palindrome Partitioniong (middle) (*^__^*)
- leetcode之Partition List
- Leetcode_partition-list
- lintcode/leetcode由易至难第4题:Array Partition I
- LeetCode 之排序 sorting
- Leetcode 4 Median of Two Sorted Arrays 两排序数组的中位数