Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Note:
You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively.
因为
第一个数组是有足够空间的 所以从最大的数开始 倒序放进空余的位置里面
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int i=m-1, j=n-1, k=m+n-1;
while (i>-1 && j>-1) A[k--]= (A[i]>B[j]) ? A[i--] : B[j--];
while (j>-1) A[k--]=B[j--];//如果说n<m 此条循环不执行 如果是n>m这个地方就把B中剩余的小的数全部放进A的前面部分就行
}
}