JavaScript 1 line cheating answer


  • 0
    Z
    /**
     * @param {number[]} nums
     * @return {void} Do not return anything, modify nums in-place instead.
     */
    var sortColors = function(nums) {
        // let count = [0,0,0];
        // for(let i of nums){count[i]++;}count[1] += count[0];count[2] += count[1];
        // for(let i = 0; i<count[0];i++){nums[i]=0;}
        // for(let i = count[0]; i<count[1];i++){nums[i]=1;}
        // for(let i = count[1]; i<count[2];i++){nums[i]=2;}
        nums.sort(function(a,b){return a -b;});
    };
    

Log in to reply
 

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