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) {
int x=0,y=0;
int[] num=new int[A.length+B.length];
int i=0;
//System.out.println(num.length);
while(x<A.length||y<B.length){
if(x==A.length){
num[i]=B[y];
y++;
}else if(y==B.length){
num[i]=A[x];
x++;
}else if(A[x]<B[y]){
num[i]=A[x];
x++;
}else{
num[i]=B[y];
y++;
}
//System.out.println("x:"+x+"y:"+y);
i++;
}
return num;
}
}
/*
* @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) {
int x=0,y=0;
int[] num=new int[A.length+B.length];
int i=0;
//System.out.println(num.length);
while(x<A.length||y<B.length){
if(x==A.length){
num[i]=B[y];
y++;
}else if(y==B.length){
num[i]=A[x];
x++;
}else if(A[x]<B[y]){
num[i]=A[x];
x++;
}else{
num[i]=B[y];
y++;
}
//System.out.println("x:"+x+"y:"+y);
i++;
}
return num;
}
}