leetcode.561 Array Partition I
来源:互联网 发布:mysql count语句 编辑:程序博客网 时间:2024/06/06 10:39
Question
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.
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].
Solution
int compare( const void* a, const void* b){ int int_a = * ( (int*) a ); int int_b = * ( (int*) b ); if ( int_a == int_b ) return 0; else if ( int_a < int_b ) return -1; else return 1;}int arrayPairSum(int* nums, int numsSize) { int sum = 0; if (numsSize == 0) return 0; qsort( nums, numsSize, sizeof(int), compare ); int i; for (i = 0; i < numsSize; i+=2) sum+=nums[i]; return sum;}
阅读全文
0 0
- leetcode#561 Array Partition I
- leetcode-561-Array Partition I
- Leetcode 561: Array Partition I
- 【LeetCode】561 Array Partition I
- [leetcode 561]Array Partition I
- leetcode 561 Array Partition I
- leetcode.561 Array Partition I
- leetcode-561(Array Partition I)
- LeetCode-561 Array Partition I
- Leetcode 561 Array Partition I
- leetcode 561:Array Partition I
- LeetCode 561 Array Partition I
- Leetcode 561:Array Partition I
- Leetcode 561 Array Partition I
- LeetCode[561]Array Partition I
- leetcode 561 Array Partition I
- LeetCode.561 Array Partition I
- Array Partition I[LeetCode 561]
- "Abort command Issued" messages appear in /var/log/messages file
- 高性能计算(HPC)
- 如何将重采样的数据扔给编码器(AVAudioFifo)
- c# winform 中如何修改listbox的某项值,如何删除某项值。
- Kotlin初体验
- leetcode.561 Array Partition I
- Guid
- 关于JS中的eval()函数问题
- 汇编--学习笔记(十四)-高级汇编技术--宏
- Java Filter过滤XSS注入非法参数
- java web 前端页面的分页逻辑
- 登陆的过滤器
- RabbitMQ与Spring整合之消息消费方
- Bugly Android热更新总结篇