Javascript 108ms


  • 0
    M

    var merge = function(nums1, m, nums2, n) {

    //two pointers
    while (m > 0 && n > 0) {
        if (nums1[m-1] >= nums2[n-1]) {
            nums1[m+n-1] = nums1[m-1];
            m--;
        } else {
            nums1[m+n-1] = nums2[n-1];
            n--;
        }
    }
    while (n > 0) {
        nums1[n-1] = nums2[n-1];
        n--;
    }
    

    };


Log in to reply
 

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