faster javascript solution


  • 0
    I

    only use toString() once for each string in the comparator.

     * @param {number[]} nums
     * @return {string}
     */
     
     function sortfunc(a,b){
         var as = a.toString();
         var bs = b.toString();
         var ab= as+bs;
         var ba = bs+as;
         return ba-ab;
     }
    var largestNumber = function(nums) {
        var result = nums.sort(sortfunc).join("");
        return parseInt(result)===0?"0":result;
    };

Log in to reply
 

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