Given two sorted integer arrays A and B, merge B into A as one sorted array.
Note:
You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.
简单的有序数组合并,不多说
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int index=m+n-1;
int curA = m-1;
int curB = n-1;
while(index>=0){
if(curA>=0&&curB>=0){
if(A[curA]>=B[curB]){
A[index--]=A[curA--];
}else {
A[index--]=B[curB--];
}
}else if(curA>=0){
A[index--]=A[curA--];
}else {
A[index--]=B[curB--];
}
}
}
}