#直接上代码吧
import java.util.*;
public class Solution {
/**
* @param A: sorted integer array A
* @param B: sorted integer array B
* @return: A new sorted integer array
*/
public int[] mergeSortedArray(int[] A, int[] B) {
// write your code here
int alen = A.length;
int blen = B.length;
int i = 0;
int j = 0;
List<Integer> list=new ArrayList<Integer>();
if(A[alen-1]<=B[0])
{
while(i<alen)
{
list.add(A[i]);
i++;
}
i=0;
while(i<blen)
{
list.add(B[i]);
i++;
}
}
else if(B[blen-1]<=A[0])
{
while(i<blen)
{
list.add(B[i]);
i++;
}
i=0;
while(i<alen)
{
list.add(A[i]);
i++;
}
}
else
{
while(j+i<alen+blen)
{
while(i<alen&&j<blen&&A[i]>=B[j])
{
list.add(B[j]);
j++;
}
while(j<blen&&i<alen&&B[j]>=A[i])
{
list.add(A[i]);
i++;
}
while(j==blen&&i<alen)
{
list.add(A[i]);
i++;
}
while(i==alen&&j<blen)
{
list.add(B[j]);
j++;
}
}
}
int[] nsz=new int[list.size()];
for(i=0;i<list.size();i++){
nsz[i] = list.get(i);
}
return nsz;
}
}