import java.util.*; public class Solution { public void merge(int A[], int m, int B[], int n) { //新建数组C,比较数组A和B的元素,把最小放入C中 //最小的数字所在数组指针后移动 int[] C = new int[m + n]; for (int i = 0, j = 0, k = 0; i < m || j < n;) { if (k == m + n) { break; } if(i<m && j<n){ if (A[i] < B[j]) { C[k] = A[i]; i++; k++; } else { C[k] = B[j]; j++; k++; } }else{ if (i == m) { C[k] = B[j]; j++; k++; continue; } if (j == n) { C[k] = A[i]; i++; k++; continue; } } } for(int i=0; i<m+n; i++){ A[i] = C[i]; }
} }
标签:数组,int,合并,最小,有序,public From: https://www.cnblogs.com/northli/p/16883918.html