(1),开辟新数组,覆盖
import java.util.*;
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int[] a=new int[m+n];
System.arraycopy(A,0,a,0,m);
System.arraycopy(B,0,a,m,n);
System.arraycopy(a,0,A,0,m+n);
Arrays.sort(A);
}
}
(2),三个指针
import java.util.*;
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int i=m-1,j=n-1,k=m+n-1;
while((i>=0)&&(j>=0))
{
if(A[i]>=B[j])
{
A[k--]=A[i--];
}
else
{
A[k--]=B[j--];
}
}
if(j>=0)
{
for(int l=0;l<=j;l++)
{
A[l]=B[l];
}
}
}
}