标签:
A subroutine of merge sort.
1 class Solution { 2 public: 3 /** 4 * @param A and B: sorted integer array A and B. 5 * @return: A new sorted integer array 6 */ 7 vector<int> mergeSortedArray(vector<int> &A, vector<int> &B) { 8 // write your code here 9 vector<int> merge; 10 int pa = 0, pb = 0; 11 while (pa < (int)A.size() && pb < (int)B.size()) { 12 if (A[pa] <= B[pb]) merge.push_back(A[pa++]); 13 else merge.push_back(B[pb++]); 14 } 15 while (pa < (int)A.size()) 16 merge.push_back(A[pa++]); 17 while (pb < (int)B.size()) 18 merge.push_back(B[pb++]); 19 return merge; 20 } 21 };
标签:
原文地址:http://www.cnblogs.com/jcliBlogger/p/4607835.html