可以用双指针思想,两个数组比较当前元素大小,小的先拿进新建立起的数组
import java.util.*;
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int[] result = new int[m+n];
int i = 0,j = 0,p = 0;
int flag = 0;
while(i<m||j<n){
if(i == m){
flag = B[j];
j++;
}
else if(j == n){
flag = A[i];
i++;
}
else if(A[i]<B[j]){
flag = A[i];
i++;
}
else{
flag = B[j];
j++;
}
result[p++] = flag;
}
for(int k = 0;k < result.length;k++){
A[k] = result[k];
}
}
}