Javascript, solution-sharing


  • 0
    C
    [javascritp]
    
    /**
     * @param {number[]} nums1
     * @param {number} m
     * @param {number[]} nums2
     * @param {number} n
     * @return {void} Do not return anything, modify nums1 in-place instead.
     */
    solution:
    var merge = function(nums1, m, nums2, n) {
        while(n){
            nums1[m++]=nums2[--n];
        }
        nums1.sort(function(val1, val2){
            return val1>val2?1:val1<val2?-1:0;
        })
    };
    
    // But, javascript, using concat and sort, why not work?
    // var merge = function(nums1, m, nums2, n) {
    //     nums1 = nums1.concat(nums2).sort(function(val1, val2){
    //         return val1>val2?1:val1<val2?-1:0;
    //     });
    // };
    /* Is the problem of increase in length */

Log in to reply
 

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