[LeetCode]Merge Sorted Array

题目:给定两个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;
	        }
	    }
}

原文地址:https://www.cnblogs.com/mengfanrong/p/5103885.html