leetcode561. Array Partition I
来源:互联网 发布:网络幼儿英语 编辑:程序博客网 时间:2024/06/08 10:00
561. Array Partition I
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: 4Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 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].
解法
public class Solution { public int arrayPairSum(int[] nums) { Arrays.sort(nums); int ret = 0; for (int i = 0; i < nums.length; i = i + 2) { ret += nums[i]; } return ret; }}
阅读全文
0 0
- leetcode561. Array Partition I
- leetcode561. Array Partition I
- leetcode561: Array Partition I
- LeetCode561. Array Partition I
- Leetcode561. Array Partition I
- python--leetcode561. Array Partition I
- 7.leetCode561.:Array Partition I
- Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- 561. Array Partition I
- Array Partition I
- 走向云计算之MapReduce原理和运行流程详解
- jquery和javascript常用方法比较
- webpack的安装与环境配置
- Scrapy爬虫实战四:糗事百科
- 【简记】Computer Networking——network layer(part three)
- leetcode561. Array Partition I
- 欢迎使用CSDN-markdown编辑器
- 生产者-消费者问题
- 使用Fitnesse对C++工程作自动化接口测试(2)
- web项目下proxool数据库连接池的使用
- android端登陆功能实现
- A Discriminative Feature Learning Approach for Deep Face Recognition 原理及在caffe实验复现
- Java实现-最小子数组
- bzoj 1001: [BeiJing2006]狼抓兔子