Question:

You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B.
Write a method to merge B into A in sorted order.

package POJ;

public class Main {

    /**
*
* 11.1 You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B.
* Write a method to merge B into A in sorted order.
*
*/
public static void main(String[] args) {
Main so = new Main();
}
public void merge(int[] a, int[] b, int lastA, int lastB){
int indexA=lastA-1;
int indexB=lastB-1;
int indexMerged=lastA+lastB-1;
while(indexA>=0&&indexB>=0){
if(a[indexA]<b[indexB]){
a[indexMerged]=b[indexB];
indexB--;
indexMerged--;
}else{
a[indexMerged]=a[indexA];
indexA--;
indexMerged--;
}
}
while(indexB>=0){
a[indexMerged]=b[indexB];
indexB--;
indexMerged--;
}
}
}

CC150 - 11.1的更多相关文章

  1. CC150 - 11.6

    Question: Given an M x N matrix in which each row and each column is sorted in ascending order, writ ...

  2. CC150 - 11.5

    Question: Given a sorted array of strings which is interspersed with empty strings, write a method t ...

  3. CC150 - 11.3

    Question: Given a sorted array of n integers that has been rotated an unknown number of times, write ...

  4. CC150 - 11.2

    Question: Write a method to sort an array of strings so that all the anagrams are next to each other ...

  5. 地区sql

    /*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...

  6. 11.8---维护x的秩(CC150)

    思路:比较easy.就是借助hashset让他有序然后就能够比较节省时间了. 答案: public static int[] getRankOfNumber(int[] a, int n){ int[ ...

  7. 11.7---叠罗汉表演节目(CC150)

    1,牛客网第一题:这其实跟找最长递增子序列是一个东西.注意的地方是,返回的是最大的dp,而不是dp[N-1]. 答案: public static int getHeight(int[] men, i ...

  8. 11.6---矩阵查找元素(CC150)

    思路,一旦提到查找就要想到二分查找. public static int[] findElement(int[][] a, int n, int m, int key) { // write code ...

  9. 11.5---含有空字符串的字符串查找(CC150)

    注意,1,"" 和 " ".是不同的,空字符串指的是"": 2,注意String的compareTo.小于是指<0.并不是==-1: ...

随机推荐

  1. Linux 磁盘的组成

    基本结构 磁道,扇区,柱面和磁头数 硬盘最基本的组成部分是由坚硬金属材料制成的涂以磁性介质的盘片,不同容量硬盘的盘片数不等.每个盘片有两面,都可记录信息. 每个磁道被分成许多扇形的区域,每个区域叫一个 ...

  2. Python Django 的 django templatedoesnotexist

    django 1.8版本的解决方案 在  setting.py 这个文件里 TEMPLATES = [ ...... #原来的 #'DIRS': [ ], //  这个 列表里添加 template路 ...

  3. QQ,MSN,Skype在线客服代码

    QQ,MSN,Skype在线客服代码 在网站建设时,为了更好的实施网站的营销型,会用到QQ,MSN等在线交流,以便客户能够快捷方便的联系我们.在这里,提供QQ,MSN的在线客服代码给大家分享: 1.Q ...

  4. 在CentOS 6.4中编译安装gcc 4.8.1

    在CentOS 6.4中编译安装gcc 4.8.1 分类: C/C++ Linux/Unix2013-11-28 21:02 1877人阅读 评论(0) 收藏 举报 原文链接:http://www.c ...

  5. Redis系列-远程连接redis并给redis加锁

    假设两台redis服务器,ip分别为:192.168.1.101和192.168.1.103,如何在101上通过redis-cli访问103上的redis呢?在远程连接103之前,先讲下redis-c ...

  6. String to Integer

    Implement function atoi to convert a string to an integer. If no valid conversion could be performed ...

  7. codeforces A. Sereja and Bottles 解题报告

    题目链接:http://codeforces.com/problemset/problem/315/A 题目意思:有n个soda bottles,随后给出这n个soda bottles的信息.已知第 ...

  8. Girls and Boys(poj 1466)

    题目描述: 给出一系列男女配对意愿信息.求一个集合中的最大人数,满足这个集合中两两的人不能配对. /* 二分图的最大独立集 因为没有给出具体的男生和女生,所以可以将数据扩大一倍,即n个男生,n个女生, ...

  9. Linux C 单链表 读取文件 并排序 实例并解释

    C的指针挺头疼的,先看一个例子: 给指针赋值和通过指针进行赋值这两种操作的差别确实让人费解.谨记区分的重要方法是:如果对左操作数进行解引用,则修改的是指针所指对象的值:    如果没有使用解引用操作, ...

  10. Jpush推送模块

      此文章已于 14:17:10 2015/3/24 重新发布到 鲸歌 Jpush推送模块     或以上版本的手机系统. SDK集成步骤 .导入 SDK 开发包到你自己的应用程序项目 •    解压 ...