JS implement


  • 0
    W
    /**
     * @param {number[]} nums1
     * @param {number} m
     * @param {number[]} nums2
     * @param {number} n
     * @return {void} Do not return anything, modify nums1 in-place instead.
     */
    var merge = function(nums1, m, nums2, n) {
        var min = Math.min(m,n);
        for(var i = 0;i<min;i++){
            if(nums1[i]>nums2[i])
                nums1.splice(i,0,nums2[i]);
        }
        if(min === m){
            nums1.concat(nums2.slice(min));
        }
    }
    

Log in to reply
 

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