题目:给定两个int型有序数组A和B,将B数组合并到A数组中(A数组空间足够)
算法:模拟插入排序,从右往左判断并往A数组中插入B数组元素
public class Solution { public void merge(int A[], int m, int B[], int n) { for (int i=0; i<n; ++i) { int j = m-1; while (j>=0 && B[i]<A[j]) { A[j+1] = A[j]; --j; } A[j+1] = B[i]; ++m; } } }
[LeetCode]Merge Sorted Array,布布扣,bubuko.com
原文地址:http://blog.csdn.net/yeweiouyang/article/details/37566191