双指针法 排两个有序数组
import java.util.*;
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int p1 = 0, p2 = 0;
//新开一个M+n大小的数组
int[] sorted = new int[m + n];
int cur;
//循环选择
while (p1 < m || p2 < n) {
if (p1 == m) {
cur = B[p2++];
} else if (p2 == n) {
cur = A[p1++];
} else if (A[p1] < B[p2]) {
cur = A[p1++];
} else {
cur = B[p2++];
}
sorted[p1 + p2 - 1] = cur;
}
//移动
for (int i = 0; i != m + n; ++i) {
A[i] = sorted[i];
}
}
}