leetcode561. Array Partition I
来源:互联网 发布:拍照解题的软件 编辑:程序博客网 时间:2024/06/01 09:53
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.
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 int arrayPairSum(int[] nums) { Arrays.sort(nums); int n = nums.length/2; int res = 0; for (int i = 0; i < n; i++) { res+=nums[i*2]; } return res; }
阅读全文
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
- C++程序内存布局
- 8-JavaScript设计模式——门面模式
- PAT-A-1061. Dating (20)
- macOS Sierra安装及使用gdb
- 虚拟机 VMware Workstation 12 安装与激活 图文教程
- leetcode561. Array Partition I
- 折半插入排序
- 如何创建快速联系人标记
- [Leetcode]_32 Longest Valid Parentheses
- Scala程序设计原则:Least Power
- Kotlin笔记(七)类成员(属性,内部类,匿名内部类)
- 170606 逆向-CrackMe之015
- 项目中身份证有效期的判断规则
- 现代软件工程-构建之法(第三单元)