simple Javascript solution


  • 0
    L
    var largestNumber = function(nums) {
        var ans = '';
        var str = [];
        for(var i in nums){
            str.push(nums[i].toString());
        }
        str = str.sort(function(a, b){return Number(b+a) - Number(a+b)});
        for(var j in str){
            if( ans === '0' && str[j] === '0') ans = '0';
            else ans = ans + str[j];
        }
        
        return ans;
        
    };
    

Log in to reply
 

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