就双指针,但是要从大到小放,不然会overwrite还没用到的elem in A[].

public class Solution {
    public void merge(int A[], int m, int B[], int n) {
      int a = m, b = n;
      while (a + b > 0) {
        int id = a + b - 1;
        if (a == 0) { A[id] = B[--b]; } 
        else if (b == 0) { A[id] = A[--a]; }
        else {
          A[id] = A[a-1] > B[b-1] ? A[--a] : B[--b];
        } 
      }
    }
}