561.Array Partition I--Python
刚开始学习Python编程,欢迎交流学习!
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.
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].
思路:由题目示例可以看出输出只要为最终的和可以了,所以不一定非得先将一个大的数组(列表)中的数据先挨个化成分开的小数组(列表),正确理解题目意思,可以输出结果就行了。所以直接对原数组(列表)排序(Python自带的函数),然后取偶数项相加就可以了。
class Solution:def arrayPairSum(self, nums):""":type nums: List[int]:rtype: int"""nums.sort()return sum(nums[::2])
561.Array Partition I--Python相关推荐
- 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 ...
- [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#561 Array Partition I
Description: Given an array of 2n integers, your task is to group these integers into n pairs of int ...
- 【刷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) 总和 ...
最新文章
- 微软私有云系列----域服务器准备
- Linux 创建yum源和软件仓库实例
- SAP WM 有无保存WM Level历史库存的Table?
- Python错误“ImportError: No module named MySQLdb”解决方法
- [Java并发编程实战] 共享对象之可见性
- 39道高级java面试题及答案(最新)
- C/C++学习之路: 多态
- OpenCV学习——形态学
- 取文字_把这4个字母输入word,会得到一段神秘文字,承载着一段历史
- C++学习之路 | PTA乙级—— 1039 到底买不买 (20 分)(精简)
- 华为云跻身Gartner报告中国三强,预示云计算市场的未来变局?
- python等待用户输入_Python等待时间,等待用户输入
- UDP和TCP 简单 区别
- vscode下搭建vue项目
- Oracle多层ifend嵌套,Excel IF函数以及IF多层嵌套如何使用,看完你就知道了
- 阿里云centos7.0安装java环境
- 谈谈时间管理--陶哲轩
- C语言中 1%3,算术什么意思啊 算数什么意思
- 织梦如何添html5播放器,织梦ckplayer视频播放器插件的介绍与使用
- 多啦a梦的python代码_分享一篇文本文档画哆啦A梦代码!
热门文章
- c语言中怎么调用自己定义的函数,c语言中怎么调用自己定义的函数?
- 12个基本的在线设计竞赛目录
- 百度变更使命后首个政府AI合作落地:在李彦宏老家
- 使用selenium和phantomjs解决爬虫中对渲染页面的爬取
- python图像处理教程,【图像处理】使用OpenCV+Python进行图像处理入门教程(二)...
- Stay hungry, Stay young
- 【计算机网络】计算机网络基础知识(三次握手,四次挥手,OSI七层网络模型)
- 一家之言:de_nuke全面分析
- jsp物流信息发布管理平台
- uniapp 小程序 加载显示插屏广告