Leetcode学习(3)—— Array Partition I
来源:互联网 发布:购买淘宝店铺价格 编辑:程序博客网 时间:2024/05/16 06:43
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.
给出一个长度为 2n 的整数数组,你的任务是将这些整数分成n组,每组两个一对,并求得 所有分组中较小的数 的总和(这个总和的值要尽可能的大)
Input: [1,4,3,2]Output: 4Explanation: n is 2, and the maximum sum of pairs is 4.
Note:
n is a positive integer, which is in the range of [1, 10000].
All the integers in the array will be in the range of [-10000, 10000].
思路:将整个数组升序排列,从下标为 0 处开始,每隔两个 取一个,并求和
class Solution(object): def arrayPartitionI(self, nums): return sum(sorted(nums)[::2])
0 0
- Leetcode学习(3)—— Array Partition I
- LeetCode——561. Array Partition I(贪心,C++)
- LeetCode Array Partition I
- leetCode---Array Partition I
- Array Partition I(leetcode)
- Leetcode-Array Partition I
- leetcode Array Partition I
- LeetCode-Easy-Java——Array Partition I
- 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
- 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
- linux命令行下载BT种子和磁力链接
- .通过编程实现,统计1~n有多少个9 (n通过参数传入)
- Android Notification.setLatestEventInfo弃用和Notification.Builder用法
- 循环与数组问题
- 课堂笔记_ 明暗处理、视点变换
- Leetcode学习(3)—— Array Partition I
- Navicat for mysql 下载安装
- leetcode82Remove Duplicates from Sorted List II
- jQuery 面试问题和答案
- java中的初始化块
- keil 注册遇到lisence manager打不开提示
- Caffe的Command Line Interfaces解析
- scikit-learn的基本用法(七)——交叉验证3
- 项目开发过程中图片素材准备