当前位置:网站首页>数组与字符串12-数组拆分
数组与字符串12-数组拆分
2022-08-03 05:25:00 【花开花落夏】
数组拆分
一 题目
来源:leetcode官网
给定长度为 2n 的整数数组 nums ,你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), …, (an, bn) ,使得从 1 到 n 的 min(ai, bi) 总和最大。返回该最大总和 。二 解题
将字符串排序,最小的和次小的一组,再次和更次一组,依次排,这样就能取到第二大,第四大等等的元素,使得min(ai, bi) 总和最大。
class Solution {
public int arrayPairSum(int[] nums) {
int tmp;
int result=0;
Arrays.sort(nums);
tmp=0;
while (tmp< nums.length){
result+=nums[tmp];
tmp+=2;
}
return result;
}
}
边栏推荐
- 自监督论文阅读笔记 SimCLRV2 Big Self-Supervised Models are Strong Semi-Supervised Learners
- 内网渗透之PPT票据传递攻击(Pass the Ticket)
- 电子元器件的分类有哪些?
- A.1#【内存管理】——1.1.3 page: struct page
- 自监督论文阅读笔记 Self-Supervised Visual Representation Learning with Semantic Grouping
- 6. What is the difference between Vector, ArrayList and LinkedList?(design, performance, safety)
- 自监督论文阅读笔记FIAD net: a Fast SAR ship detection network based on feature integration attention and self
- 电子元器件和电子元件的区别有那些?
- opencv目标检测
- cb板上常用的电子元器件都有哪些?
猜你喜欢
block底层探索
自监督论文阅读笔记 Ship Detection in Sentinel 2 Multi-Spectral Images with Self-Supervised Learning
SolidWorks 操作视频 | 流体分析结果演示
自监督论文阅读笔记 TASK-RELATED SELF-SUPERVISED LEARNING FOR REMOTE SENSING IMAGE CHANGE DETECTION
基于南航app直减自动出票
Dynamic adjustment of web theme (2) Extraction
内网渗透之PPT票据传递攻击(Pass the Ticket)
自我监督学习和BERT模型
自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning
MySql的Sql语句的练习(试试你能写出来几道呢)
随机推荐
SolidWorks 操作视频 | 流体分析结果演示
9. Please introduce the class loading process, what is the parent delegation model?
三、final、finally、 finalize有什么不同?
window下VS2022封装静态库以及调用静态库
g++ parameter description
A.1#【内存管理】——1.1.4 node: 初始化
001_旭日X3派初探:开箱测试
什么是参数化设计,通过实操了解一下? | SOLIDWORKS 操作视频
关于芯片你了解吗?
各种cms getshell技巧
常见的电子元器件分类介绍-唯样商城
STM32启动文件的选择
自监督论文阅读笔记 Multi-motion and Appearance Self-Supervised Moving Object Detection
IPC通信 - 管道
BurpSuite 进阶玩法
【第三周】ResNet+ResNeXt
浮点型数据在内存中存储的表示
电容器和电池有什么不同?
2021-03-22
5. What is the difference between int and Integer?