题解 | #合并两个有序的数组#
合并两个有序的数组
http://www.nowcoder.com/questionTerminal/89865d4375634fc484f3a24b7fe65665
Java实现
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int i = m - 1;
int j = n - 1;
int k = m + n - 1;
while(i >= 0 && j >= 0) {
if (A[i] >= B[j]) {
A[k] = A[i];
i--;
k--;
}
else {
A[k] = B[j];
k--;
j--;
}
}
while (i >= 0) {
A[k] = A[i];
i--;
k--;
}
while (j >= 0) {
A[k] = B[j];
k--;
j--;
}
}
}