Leetcode刷题记录[java]——561 Array Partition I
一、前言
二、题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].
三、解题思路
1 class Solution { 2 public int arrayPairSum(int[] nums) { 3 Arrays.sort(nums); 4 int result = 0; 5 for (int i = 0; i < nums.length; i += 2) { 6 result += nums[i]; 7 } 8 return result; 9 } 10 }
转载于:https://www.cnblogs.com/Myoungs/p/7832870.html
Leetcode刷题记录[java]——561 Array Partition I相关推荐
- 算法记录 牛客网 leetcode刷题记录
算法记录 & 牛客网 & leetcode刷题记录 解题思路 STL容器 常用算法模板 堆排序 插入排序 快速排序 BFS层序遍历 二叉树 JZ55 二叉树的深度 BST(binary ...
- LeetCode刷题记录12——232. Implement Queue using Stacks(easy)
LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...
- LeetCode刷题记录11——290. Word Pattern(easy)
LeetCode刷题记录11--290. Word Pattern(easy) 目录 LeetCode刷题记录11--290. Word Pattern(easy) 题目 语言 思路 源码 后记 题目 ...
- LeetCode刷题记录10——434. Number of Segments in a String(easy)
LeetCode刷题记录10--434. Number of Segments in a String(easy) 目录 LeetCode刷题记录9--434. Number of Segments ...
- LeetCode刷题记录9——58. Length of Last Word(easy)
LeetCode刷题记录9--58. Length of Last Word(easy) 目录 LeetCode刷题记录9--58. Length of Last Word(easy) 题目 语言 思 ...
- LeetCode刷题记录8——605. Can Place Flowers(easy)
LeetCode刷题记录8--605. Can Place Flowers(easy) 目录 LeetCode刷题记录8--605. Can Place Flowers(easy) 题目 语言 思路 ...
- LeetCode刷题记录7——824. Goat Latin(easy)
LeetCode刷题记录7--824. Goat Latin(easy) 目录 LeetCode刷题记录7--824. Goat Latin(easy) 题目 语言 思路 后记 题目 题目需要将一个输 ...
- LeetCode刷题记录6——696. Count Binary Substrings(easy)
LeetCode刷题记录6--696. Count Binary Substrings(easy) 目录 LeetCode刷题记录6--696. Count Binary Substrings(eas ...
- LeetCode刷题记录5——441. Arranging Coins(easy)
LeetCode刷题记录5--441. Arranging Coins(easy) 目录 LeetCode刷题记录5--441. Arranging Coins(easy) 题目 语言 思路 后记 题 ...
最新文章
- 1月书讯 | 开年多本重点书
- 01----mockjs介绍
- HTMLCollection元素的For循环
- 半潜式深海平台动力定位控制技术研究
- bzoj2326 [HNOI2011]数学作业
- 升序排列python_Python3基础 sort 将一个列表中的值升序排列
- java utils
- SAP Spartacus 基于行项目的订单取消功能(order cancel)实现
- 【NBIoT无线模块DTU数传电台】串口服务器RS232/RS485端口工业路由信号传输
- NagiosQL 3的安装
- 中缀表达式 转成 后缀表达式
- android怎么备份镜像文件,如何备份手机系统镜像? - Android系统区 - 无忧启动论坛 - Powered by Discuz!...
- js前置递增和后置递增
- 循序渐进学SAP系列(一):--SAP该如何入门
- 苹果手机用什么蓝牙耳机好?适合苹果的音乐蓝牙耳机推荐
- 【成神之路】开放设计编程相关面试题
- 数据库DevOps:我们如何提供安全、稳定、高效的研发全自助数据库服务-iDB/DMS企业版...
- color demura原理_AMOLED中的补偿技术之外部光学补偿(Demura)
- 5款提高办公效率的好软件,最后一个绝了
- 多家自媒体平台实现内容互通:自媒体平台的圈地运动