1、
Given two sorted integer arrays A and B, merge B into A as one sorted array.
A = [1, 2, 3, empty, empty]
, B = [4, 5]
After merge, A will be filled as [1, 2, 3, 4, 5]
2、
public static void mergeSortedArray(int[] A,int m,int n, int[] B) { int i = m-1, j = n-1, index = m + n - 1; //从大到小 while (i >= 0 && j >= 0) { if (A[i] > B[j]) { A[index--] = A[i--]; } else { A[index--] = B[j--]; } } while (i >= 0) { A[index--] = A[i--]; } while (j >= 0) { A[index--] = B[j--]; } }