[LintCode] 合并排序数组
A subroutine of merge sort.
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
vector<int> merge;
int pa = , pb = ;
while (pa < (int)A.size() && pb < (int)B.size()) {
if (A[pa] <= B[pb]) merge.push_back(A[pa++]);
else merge.push_back(B[pb++]);
}
while (pa < (int)A.size())
merge.push_back(A[pa++]);
while (pb < (int)B.size())
merge.push_back(B[pb++]);
return merge;
}
};
[LintCode] 合并排序数组的更多相关文章
- lintcode:合并排序数组 II
题目: 合并排序数组 II 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A = [1, 2, 3, empty, empty] B = [4,5] 合并之后A将变成[1,2,3,4,5] ...
- LintCode——合并排序数组II
描述:合并两个排序的整数数组A和B变成一个新的数组 样例:给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 1.Python:先将数组B加到数组A之后,然后 ...
- [LintCode] 合并排序数组II
class Solution { public: /** * @param A: sorted integer array A which has m elements, * but size of ...
- lintcode:合并排序数组
题目: 合并排序数组 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 挑战 你能否优化你的算法,如果 ...
- LintCode之合并排序数组II
题目描述: 分析:题目的意思是把数组A和数组B合并到数组A中,且数组A有足够的空间容纳A和B的元素,合并后的数组依然是有序的. 我的代码: public class Solution { /* * @ ...
- lintcode: 把排序数组转换为高度最小的二叉搜索树
题目: 把排序数组转换为高度最小的二叉搜索树 给一个排序数组(从小到大),将其转换为一棵高度最小的排序二叉树. 样例 给出数组 [1,2,3,4,5,6,7], 返回 4 / \ 2 6 / \ / ...
- LintCode之合并排序数组
题目描述: 我的代码: public class Solution { /* * @param A: sorted integer array A * @param B: sorted integer ...
- [LintCode笔记了解一下]64.合并排序数组
Given two sorted integer arrays A and B, merge B into A as one sorted array. 思路: 因为A的后面的部分都是空的留出来给我们 ...
- 64. 合并排序数组.md
描述 合并两个排序的整数数组A和B变成一个新的数组. 你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素. 您在真实的面试中是否遇到过这个题? 样例 给出 A = [1, 2, ...
随机推荐
- ADB 高级应用
一.利用无线来查看adb shell > adb tcpip 5555 连接: > adb connect IP:5555 见后文<调试注意事项> 二.模拟按键 ...
- SQL中的join操作总结(非常好)
1.1.1 摘要 Join是关系型数据库系统的重要操作之一,SQL Server中包含的常用Join:内联接.外联接和交叉联接等.如果我们想在两个或以上的表获取其中从一个表中的行与另一个表中的行匹配的 ...
- 0055 <mvc:default-servlet-handler />不能同时访问静态资源和动态资源的问题
刚才在折腾的时候,发现applicationContext.xml中配置了<mvc:default-servlet-handler />后,能访问静态资源,却不能访问动态资源了:注释掉之后 ...
- SpringBoot入门系列:第三篇 日志输出
http://blog.csdn.net/lxhjh/article/details/51752419
- continue和pass測试
>>> for i in range(1,10): print i try:int('sdfa') except:pass 1 2 3 4 5 6 7 8 9 >>> ...
- 数据库设计(六)第二范式(2NF)?
For a table to be in the Second Normal Form, it must satisfy two conditions: The table should be in ...
- 安装 RabbitMQ (WINDOWS)
基础知识: RabbitMQ 是一个开源的MQ,使用 Erlang 写成. MQ 全称是Message Queue (消息队列), 是一种应用程序对应用程序的通信方法.通过消息队列,应用程序之间可以 ...
- 关于selenium IDE找不到元素bug
使用 selenium IDE 录制脚本,经常会发生 这样一种错误. 页面上,明明存在这个元素,就是找不到. 其实原理很简单 , 按钮 点击,没有时间延迟,但是页面加载,需要一段时间. 页面元素还 ...
- website 合集
1. oracle http://asktom.oracle.com ( 英文 ) http://itpub.net ( 中文 ) https://www.oracle.com/communitie ...
- 使用AllocConsole()添加调试用控制台
AllocConsole 函数 为调用进程分配一个新的控制台. 使用步骤: 1. AllocConsole(); //分配控制台 2. HANDLE g_hOutput=GetStdHandle( ...