My 0ms C solution


  • -2
    X
    void merge(int* nums1, int m, int* nums2, int n) 
     {
    
     int lpos = 0, rpos = 0, tmpos = 0;
     int* tem = (int*)malloc(sizeof(int)*(m+n));
    
     while(lpos < m && rpos < n)
     {
        if(nums1[lpos] < nums2[rpos])
            tem[tmpos++] = nums1[lpos++];
        else
            tem[tmpos++] = nums2[rpos++];
     }
     while(lpos < m)
     {
         tem[tmpos++] = nums1[lpos++];
     } 
     while(rpos < n)
     {
         tem[tmpos++] = nums2[rpos++];
     }
    
     int i = 0;
     for(i=0;i<m+n;i++)
     {
        nums1[i] = tem[i];
     }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.