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) {
// write your code here
int pa = m - , pb = n - , p = m + n - ;
while (pa >= && pb >= ) {
if (A[pa] >= B[pb]) A[p--] = A[pa--];
else A[p--] = B[pb--];
}
while (pb >= ) A[p--] = B[pb--];
}
};

[LintCode] 合并排序数组II的更多相关文章

  1. lintcode:合并排序数组 II

    题目: 合并排序数组 II 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A = [1, 2, 3, empty, empty] B = [4,5] 合并之后A将变成[1,2,3,4,5] ...

  2. 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之后,然后 ...

  3. LintCode之合并排序数组II

    题目描述: 分析:题目的意思是把数组A和数组B合并到数组A中,且数组A有足够的空间容纳A和B的元素,合并后的数组依然是有序的. 我的代码: public class Solution { /* * @ ...

  4. 6. 合并排序数组 II

    6. Merge Two Sorted Arrays Description Merge two given sorted integer array A and B into a new sorte ...

  5. [容易]合并排序数组 II

    题目来源:http://www.lintcode.com/zh-cn/problem/merge-sorted-array/

  6. [LintCode] 合并排序数组

    A subroutine of merge sort. class Solution { public: /** * @param A and B: sorted integer array A an ...

  7. lintcode 中等题:搜索旋转排序数组II

    题目 搜索旋转排序数组 II 跟进“搜索旋转排序数组”,假如有重复元素又将如何? 是否会影响运行时间复杂度? 如何影响? 为何会影响? 写出一个函数判断给定的目标值是否出现在数组中. 样例 给出[3, ...

  8. lintcode:合并排序数组

    题目: 合并排序数组 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 挑战 你能否优化你的算法,如果 ...

  9. lintcode-64-合并排序数组 II

    64-合并排序数组 II 合并两个排序的整数数组A和B变成一个新的数组. 注意事项 你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素. 样例 给出 A = [1, 2, 3, ...

随机推荐

  1. 关于UML图形/图示数量总结

    http://www.uml.org/ 第一种说法: UML - Unified Modeling Language UML 共定义了9种图,包括4种结构图和5种形为图: //4种结构图: 类图 对象 ...

  2. WPF SL 属性生成器

    在开发WPF 和SL应用的时候通用会用到MVVM模式,每次写到类属性的时候要不断的写属性更新时通知方法,写多了就嫌烦,就手写了个属性生成工具,在属性更新的时候添加了更新通知方法. 工具中支持自定义类对 ...

  3. mac 安装2个xcode 时会导致找不到xcodebuild

    mac 安装2个xcode 时会导致找不到xcodebuild 解决方案: sudo  xcode-select --switch /Applications/Xcode.app/Contents/D ...

  4. Android之ImageButton控件基础操作

    控件绑定(前台对应控件的id属性要设置为imageButton_light) private ImageButton imageButton_light;//定义一个ImageButton控件对象,名 ...

  5. 自制MVC框架原理介绍

    当初用jsp开发程序时,因为很多东西写在一起混淆的,项目做大或者变更的时候就会很吃力,联动性太大,有时修改视图的东西都可能会影响业务逻辑,分层不明确. 后来听说了Struts MVC,做过几个示例,层 ...

  6. mongodb - mongotop

    mongodb - mongotop # ./mongotop 2016-03-12T16:37:32.141+0800 connected to: 127.0.0.1 ns total read w ...

  7. swipeRefreshLayout与webview滑动冲突

    遇到这么个bug,webview使用swipeRefreshLayout时,下拉时事件不会被webview捕获,而是执行swipeRefreshLayout的刷新,网上一大堆一大堆的解决办法,都是什么 ...

  8. macbook使用“终端”远程登录linux主机

    登录mac系统后,依次打开顶部菜单,“前往” -> “应用程序” -> “实用工具” -> “终端”,如下图:   在打开的终端页面,输入如下代码: ssh user@hostnam ...

  9. sklearn word2vec 实践

    源代码: https://blog.csdn.net/github_38705794/article/details/75452729 一.复现时报错: Traceback (most recent ...

  10. swiper动态加载数据滑动失效,ajax执行后swiper.js的效果消失问题

    使用swiper.js做一些动效时,如果进行了ajax,并且重新把DOM写入到HTML代码中,会导致swiper.js的特效消失的问题.原因是ajax加载后,原先new 的Swiper对象,不认识新来 ...