Given two sorted integer arrays A and B, merge B into A as one sorted array.
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int Aindex = m-1;
int Bindex = n-1;
int index = m+n -1;
while(Bindex>=0){
if(Aindex<0 || (A[Aindex] < B[Bindex])){
A[index] = B[Bindex];
Bindex--;
}
else{
A[index] = A[Aindex];
Aindex--;
}
index--;
}
}
}
沒有留言:
張貼留言