// 32ms
1 class Solution { 2 public: 3 void merge(int A[], int m, int B[], int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int i,j,k; 7 for(i=m-1;i>=0;i--) 8 { 9 A[i+n]=A[i]; 10 } 11 i=n; 12 j=0; 13 k=0; 14 while(i<m+n&&j<n) 15 { 16 if(A[i]<=B[j]) 17 { 18 A[k]=A[i]; 19 k++; 20 i++; 21 } 22 else 23 { 24 A[k]=B[j]; 25 k++; 26 j++; 27 } 28 } 29 while(j<n) 30 { 31 A[k]=B[j]; 32 k++; 33 j++; 34 } 35 } 36 };