1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| class Solution { public void merge(int[] A, int m, int[] B, int n) { int len = m + n; for (int i = len - 1; i >= 0; i--) { if (m == 0){ for (int j = 0; j < n; j++) { A[j] = B[j]; } return; }
if (n == 0){ return; }
if (A[m-1] > B[n-1]){ A[i] = A[m-1]; m --; }else { A[i] = B[n-1]; n--; } } } }
|