[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, ...
随机推荐
- FreeBSD Top States
转自:http://blog.csdn.net/fcoolx/article/details/4412196 select Process is blocked in the select(2) sy ...
- Python 统计代码的行数,Python脚本 统计代码
# coding=utf-8 import os import time # 需要统计的文件夹或者文件,这是在windows下运行的,如果使用Linux系统可以使用 basedir = '/app/l ...
- 大型跨境电商 JVM 调优经历
前提: 某大型跨境电商业务发展非常快,线上机器扩容也很频繁,但是对于线上机器的运行情况,特别是jvm内存的情况,一直没有一个统一的标准来给到各个应用服务的owner.经过618大促之后,和运维的同学讨 ...
- Oracle之函数concat、lpad
一.引言 程序测试需要生成大量的测试数据,且测试数据有主键,主键自增,于是决定用存储过程来实现,经过半天的查资料终于完成了,记录之,学习之 二.存储过程 格式: CREATE PROCEDURE re ...
- 关于mysql内存表的一个帖子(转载)
地址:http://bbs.csdn.net/topics/360030699 引用楼主 zgycsmb 的回复:问:1mysql的内存表性能怎么样2mysql的内存表与system v 这种共享内存 ...
- JVM Specification 9th Edition (3) Chapter 2. The Structure of the Java Virtual Machine
Chapter 2. The Structure of the Java Virtual Machine 内容列表 2.1. The class File Format (class文件的格式) 2. ...
- OSGI
OSGi(Open Service Gateway Initiative)技术是面向Java的动态模型系统.OSGi服务平台向Java提供服务,这些服务使Java成为软件集成和软件开发的首选环境.Ja ...
- TDS协议解析
文章来自:http://freetds.cvs.sourceforge.net/*checkout*/freetds/freetds/doc/tds.html 该网站是免费的专门介绍TDS协议的,网址 ...
- hdu5536 Chip Factory 字典树+暴力 处理异或最大 令X=(a[i]+a[j])^a[k], i,j,k都不同。求最大的X。
/** 题目:hdu5536 Chip Factory 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:给定n个数,令X=(a[i]+a[j] ...
- Tuning 14 Using Oracle Data Storage Structures Efficiently
90% 是Heap table Cluster 集群表, index-organized table: 就是把索引和表 和二为一了. partitioned table:表非常大, 逻辑上是一个大表, ...