leetcode#561 Array Partition I
Description:
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.
显然,将排序后的数列的相邻两个数配对是最大的匹配方法。
class Solution {
public:int arrayPairSum(vector<int>& nums) {sort(nums.begin(), nums.end());int n = nums.size() / 2;int sum = 0;for (int i=0; i<n; i++) {sum += nums[i * 2];}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(数组划分)
翻译 原文 Given an array of 2n integers, your task is to group these integers into n pairs of integer, s ...
- 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 ...
- 【刷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 ...
- 561. 数组拆分 I(javascript)561. Array Partition I
给定长度为 2n 的整数数组 nums ,你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), -, (an, bn) ,使得从 1 到 n 的 min(ai, bi) 总和 ...
最新文章
- Express中间件工作原理介绍
- RPA技术干货 | RPA防锁屏运行技巧
- scikit-learn点滴
- 找出第i个小元素(算法导论第三版9.2-4题)
- 【计算机网络】wireshark数据流追踪、图像抓取(转)
- 迷你世界无限迷你币体验服务器,迷你世界体验服无限迷你币
- 选择器、像素和百分比、颜色单位、文档流-css基础
- 7. 代码中特殊的注释技术——TODO、FIXME和XXX的用处
- JS 代码调试经验总结(菜鸟必读)
- cnchar.js 获取汉字的拼音和笔画数的js库 cnchar2.0 支持繁体字、笔画顺序、多音字词
- ecshop二次开发bug(一)
- Tracking 1.3 Online Trackers
- 【Unity3D实战】摇摆直升机开发实战(一)
- 5、提取snp indel 位点
- 贷款买房,利息怎么算?等额本金与等额本息
- U盘“请将磁盘插入U盘”,主控显示“chipYC2019”处理
- 计算机一级excel中模拟运算,2017年计算机一级《MS Office》操作试题及答案
- 使用FFMPEG工具包移除视频的水印
- SqlServer数据库常用sql语句
- element组件---其他组件
热门文章
- Keras 之 LSTM 有状态模型(stateful LSTM)和无状态模型(stateless LSTM)
- linux 移动某个文件夹及其所有子文件夹内指定类型的文件
- 有时候要跌到谷底,才会慢慢变好
- LabVIEW编程LabVIEW开发需要加班吗
- VB.net小技巧——读取文本文件并显示到文本框中
- 小白入门计算机视觉系列——ReID(一):什么是ReID?如何做ReID?ReID数据集?ReID评测指标?
- 想分享给马云和李开复的一篇文章
- linux移植嵌入式系统,嵌入式系统学习——S3C2451之Linux移植步骤
- void指针(void *的用法)
- ElementUI表单校验rules封装