LintCode 合并排序数组
来源:互联网 发布:php ci框架 编辑:程序博客网 时间:2024/05/16 07:56
合并排序数组
合并两个排序的整数数组A和B变成一个新的数组。
样例
给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6]
code
class Solution {public: /** * @param A and B: sorted integer array A and B. * @return: A new sorted integer array */ vector<int> mergeSortedArray(vector<int> &A, vector<int> &B) { // write your code here const int m = A.size(), n = B.size(); vector<int> res(m+n, 0); int i=0, j=0, k = 0; while(i < m && j < n) { if(A[i] < B[j]) res[k++] = A[i++]; else res[k++] = B[j++]; } while (i < m) res[k++] = A[i++]; while (j < n) res[k++] = B[j++]; return res; }}
0 0
- LintCode 合并排序数组
- LintCode: 合并排序数组
- lintcode ----合并排序数组
- LintCode:合并排序数组
- lintcode--合并排序数组
- Lintcode合并排序数组
- Lintcode:合并排序数组
- LintCode 合并排序数组 II
- 合并排序数组(LintCode)
- LintCode(easy)合并排序数组
- LintCode-合并排序数组 II
- LintCode 6 合并排序数组
- 【lintcode笔记】合并排序数组
- Lintcode 合并排序数组 II
- LintCode-合并排序数组 II
- 【LintCode】合并排序数组 II
- Lintcode合并排序数组 II
- LintCode Python 合并排序数组
- 在纯净的linux中配置安装caffe直到可以训练和测试自己的数据集(1/2)
- ZOJ-3793-First Digit
- UVA - 1588 Kickdown
- Eclipse快捷键 10个最有用的快捷键
- 00
- LintCode 合并排序数组
- Android自定义View的实现方法,带你一步步深入了解View(四)
- 论文相关
- eclipse 从Git导入maven项目
- 输入字符串,输出各个字符的个数(map用法小例)
- 美女图片网站推广方法
- C/C++中四种不同的类型转换方式
- 洛谷1071 潜伏者
- java中调用dll文件的两种方法