牛客刷题记录集
合并两个有序的数组
http://www.nowcoder.com/questionTerminal/89865d4375634fc484f3a24b7fe65665
1、合并两个有序数组:
使用双指针,从后向前。
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int right=m+n-1;
int curA=m-1;
int curB= n-1;
while(curA>=0&&curB>=0){
if(A[curA]>B[curB]){
A[right--]=A[curA--];
}else{
A[right--]=B[curB--];
}
}
while(curA>=0){
A[right--]=A[curA--];
}
while(curB>=0){
A[right--]=B[curB--];
}
}
} 
