合并排序数组 II
来源:互联网 发布:订货系统源码 编辑:程序博客网 时间:2024/04/25 19:44
合并两个排序的整数数组A和B变成一个新的数组。
样例
给出A = [1, 2, 3, empty, empty] B = [4,5]
合并之后A将变成[1,2,3,4,5]
注意:你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素。
class Solution {public: /** * @param A: sorted integer array A which has m elements, * but size of A is m+n * @param B: sorted integer array B which has n elements * @return: void */ void mergeSortedArray(int A[], int m, int B[], int n) { int k=m+n-1; int i=m-1; int j=n-1; while(i>=0 && j>=0) { if(A[i]>B[j]) A[k--]=A[i--]; else A[k--]=B[j--]; } while(j>=0) { A[k--]=B[j--]; } }};
0 0
- 合并排序数组 II
- 合并排序数组 II
- 合并排序数组II
- 合并排序数组 II
- 合并排序数组 II
- 题目:合并排序数组 II
- LintCode 合并排序数组 II
- LintCode-合并排序数组 II
- Lintcode 合并排序数组 II
- LintCode-合并排序数组 II
- 【LintCode】合并排序数组 II
- Lintcode合并排序数组 II
- Lintcode合并排序数组 II
- lintcode-合并排序数组II-64
- 合并排序数组 II——LintCode
- lintcode之 合并排序数组 II
- LintCode(easy)合并排序数组II
- LintCode 64 合并排序数组 II
- This End Up: Using Device Orientation
- 图像翻转
- js 日期格式转换
- java基础将一个int数组转换成一个字符串
- jFileChooser showSaveDialog 保存文件
- 合并排序数组 II
- opencv学习笔记8:跟踪与运动
- Android计算器开发实例
- 杨子江gre填空词汇分类整理
- CodeForces 124B Permutations
- java中的基本数据类型与封装类
- iOS TableView实现QQ好友列表(二)
- Codeforces546C:Soldier and Cards
- java用BufferedImage转换图片大小并保存