Given two sorted integer arrays A and B, merge B into A as one sorted array.
Note:
You may assume that A has enough space (size that is greater or equal to m +
n) to hold additional elements from B. The number of elements initialized in A and B are
m and n respectively.
思路:如果A的空间够,那么从后往前开始填充即可
void merge(int A[], int m, int B[], int n) { int i,j=m-1; int cur= m+n-1; for(i=n-1;i>=0;) { if(A[j] > B[i]) A[cur--] = A[j--]; else A[cur--] = B[i--]; } }
原文地址:http://blog.csdn.net/yusiguyuan/article/details/45023657