标签:style blog color io ar for sp div on
级别简单,用了额外的空间,不知道这个可不可以改进,最后到时ac了。
public class Solution { public void merge(int A[], int m, int B[], int n) { int res[] = new int[m + n]; int pm = 0; int pn = 0; int i = 0; for (; i < m + n; i++) { if (pm == m) { if (pn == n) { break; } else { res[i] = B[pn]; pn++; } } else if (pn == n) { if (pm == m) { break; } else { res[i] = A[pm]; pm++; } } else { res[i] = (A[pm] > B[pn] ? B[pn] : A[pm]); if (A[pm] > B[pn]) { pn++; } else { pm++; } } } for (int j = 0; j < m + n; j++) { A[j] = res[j]; } } }
标签:style blog color io ar for sp div on
原文地址:http://www.cnblogs.com/bluedreamviwer/p/4052833.html