标签:solution ret new write array color int pre return
class Solution { /** * @param A and B: sorted integer array A and B. * @return: A new sorted integer array */ public int[] mergeSortedArray(int[] A, int[] B) { // Write your code here int n = A.length + B.length; int[] rst = new int[n]; int a = 0; int b = 0; int i = 0; while (a < A.length && b < B.length) { if (A[a] < B[b]) { rst[i++] = A[a++]; } else { rst[i++] = B[b++]; } } while (a < A.length) { rst[i++] = A[a++]; } while (b < B.length) { rst[i++] = B[b++]; } return rst; } }
标签:solution ret new write array color int pre return
原文地址:http://www.cnblogs.com/codingEskimo/p/6922565.html