Largest number
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9] , the largest formed number is 9534330 .
Note:the result May is very large, so you need to return a string instead of an integer.
https://leetcode.com/problems/largest-number/
When sorting, put two numbers together and try to find out who's big or small.
There is a case of [0,0], too poisonous.
1 /**2 * @param {number[]} nums3 * @return {string}4 */5 varLargestnumber =function(nums) {6Nums =nums.sort (sorting);7 varCount = 0;8 for(vari = 0; i < nums.length-1; i++){9 if(Nums[i] = = = 0 ){Tencount++; One}Else{ A Break; - } - } the while(count--){ - Nums.shift (); - } - returnNums.join (' '); + - functionsorting (A, b) { +A =a.tostring (); Ab =b.tostring (); at if(parseint (A + B) > parseint (b +a)) { - return-1; -}Else if(parseint (A + B) < parseint (b +a)) { - return1; -}Else{ - return0; in } - } to};
[Leetcode] [JavaScript] Largest number