Chinaunix首页 | 论坛 | 博客
  • 博客访问: 255912
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-03-16 10:54:26

Given two sorted integer arrays A and B, merge B into A as one sorted array.

Note:
You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are mand n respectively.



public void merge(int A[], int m, int B[], int n) {

int[] result=new int[m+n];
int i=0;
int j=0;
int k=0;
if(m==0&&n==0)
return;
while(i
if(A[i]>=B[j]){
result[k]=B[j];
j++;
k++;
}
else {
result[k]=A[i];
i++;
k++;
}
}
 
if(i
for(;i
result[k]=A[i];
 
k++;
}
}
else {
//细细检查代码
for(;j
result[k]=B[j];

k++;
}
}
 
for(int r=0;r
A[r]=result[r];
}
}
阅读(181) | 评论(0) | 转发(0) |
0

上一篇:SpiralMatrixTwo

下一篇:Search a 2D Matrix

给主人留下些什么吧!~~