合并排列数组

class Solution {
/**
* @param A and B: sorted integer array A and B.
* @return: A new sorted integer array
*/
public ArrayList mergeSortedArray(ArrayList A, ArrayList B) {
// write your code here
ArrayList merge = new ArrayList();
int aSize = A.size();
int bSize = B.size();
int i = 0;
int j = 0;
while(i<aSize && j<bSize){
if(A.get(i)< = B.get(j)){
merge.add(A.get(i));
i++;
}else{
merge.add(B.get(j));
j++;
}
}
while(i<aSize){
merge.add(A.get(i));
i++;
}
while(j<bSize){
merge.add(B.get(j));
j++;
}
return merge;
}
}

posted @ 2017-08-22 02:04  逸文皓  阅读(83)  评论(0编辑  收藏  举报