LeetCode 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: 4
Explanation: 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 sum = 0;for (int i = 0; i < nums.length; i+=2) {sum += nums[i];}return sum;}
LeetCode 561 Array Partition I(数组划分)相关推荐
- [LeetCode]561. Array Partition I (数组分区 1)
561. Array Partition I Given an array of 2n integers, your task is to group these integers into n pa ...
- LeetCode 561. Array Partition I
题目: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say ...
- leetcode#561 Array Partition I
Description: Given an array of 2n integers, your task is to group these integers into n pairs of int ...
- Leetcode PHP题解--D14 561. Array Partition I
561. Array Partition I 题目链接 561. Array Partition I 题目分析 本题给了一个数组,要求将数组分为n个只有2个元素的一对. 使得每对数字中最小的数加起来的 ...
- Leetcode刷题记录[java]——561 Array Partition I
一.前言 二.题561 Array Partition I Given an array of 2n integers, your task is to group these integers in ...
- 561.Array Partition I--Python
刚开始学习Python编程,欢迎交流学习! 561.Array Partition I Given an array of 2n integers, your task is to group the ...
- 561. 数组拆分 I(javascript)561. Array Partition I
给定长度为 2n 的整数数组 nums ,你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), -, (an, bn) ,使得从 1 到 n 的 min(ai, bi) 总和 ...
- 【刷leetcode,拿Offer-009】561. Array Partition I(贪心,C++)
题目链接 Given an array of 2n integers, your task is to group these integers into n pairs of integer, sa ...
- 561. Array Partition I
原题 Given an array of 2n integers, your task is to group these integers into n pairs of integer, say ...
最新文章
- C/MFC如何获得应用程序当前路径(整理)
- 程序员有趣的面试智力题(转)
- 微信小程序长按保存图片
- python 变量
- 后“量子霸权”时代你不可错过的几本好书
- mt4双线macd_手机版MT4怎样添加双线MACD指标 手机MT4双线MACD设置方法
- 解决ssh登录Host key verification failed
- 一个都不能少:全面认识IE插件
- itools 苹果录屏大师 java_AirPlayer电脑版(itools苹果录屏大师)下载|AirPlayer电脑免费版...
- 谷歌浏览器为什么不能自定义安装路径?
- 编写业务逻辑代码-清晰可维护是很重要的
- 【UI】优秀的网站欣赏以及分析
- rsa签名算法c语言,数字签名算法rsa
- CMP SUB 区别
- 8K播放网络全终端播放器H5播放器网页直播/点播播放器EasyPlayer和vlc播放RTSP流地址不兼容问题排查解决
- 关于No enclosing instance of type MyProject is accessible的报错
- 父组件给孙子组件传值
- 使用jol查看对象内部布局
- echarts map (echarts地图)使用总结
- armbian n1 桌面_N1盒子初体验(降级+刷armbian)