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. mysql数据库性能优化(包括SQL,表结构,索引,缓存)

    优化目标减少 IO 次数IO永远是数据库最容易瓶颈的地方,这是由数据库的职责所决定的,大部分数据库操作中超过90%的时间都是 IO 操作所占用的,减少 IO 次数是 SQL 优化中需要第一优先考虑,当 ...

  2. 12 day 1

    #include <cstdio> int i,j,m,n,t; long long f[6000][6000]; inline int min(int a,int b){ return ...

  3. Redis使用介绍

    Redis 是一个高性能的key-value数据库. redis的出现,很大程度补偿了memcached这类keyvalue存储的不足,在部 分场合可以对关系数据库起到很好的补充作用.它提供了Pyth ...

  4. 【python】format函数格式化字符串的用法

    来源:http://www.jb51.net/article/63672.htm 自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式 ...

  5. ios获取一个文件夹下的文件(夹)列表

    NSArray* ary=[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[[NSBundle mainBundle] pathFo ...

  6. UITableView:下拉刷新和上拉加载更多

    [转载请注明出处] 本文将说明让UIScrollView支持"下拉刷新"和"上拉加载更多"的实现机制,并实现一个可用的tableView子类,以下主要以&quo ...

  7. Razor入门

    一.Razor简介Razor不是编程语言,它是一种允许您向网页中嵌入基于服务器的代码的标记语法,也就是可以在html网页中嵌入的写入C#代码,Razor在VS中有自动提示,使用起来会方便一点,如下代码 ...

  8. 为什么C++类定义中,数据成员不能被指定为自身类型,但可以是指向自身类型的指针或引用?为什么在类体内可以定义将静态成员声明为其所属类的类型呢 ?

    static的成员变量,不是存储在Bar实例之中的,因而不会有递归定义的问题. 类声明: class Screen: //Screen类的声明 1 类定义: class Screen{ //Scree ...

  9. Android主题换肤实现

    本系列文章主要是对一个Material Design的APP的深度解析,主要包括以下内容 基于Material Design Support Library作为项目整体框架.对应博文:Android ...

  10. Struts2中配置默认Action

    1.当访问的Action不存在时,页面会显示错误信息,可以通过配置默认Action处理用户异常的操作:2.配置方法:    在struts.xml文件中的<package>下添加如下内容: ...