标签:
1. Largest Number
For example, given [3, 30, 34, 5, 9]
, the largest formed number is 9534330
.
1 /** 2 * @param {number[]} nums 3 * @return {string} 4 */ 5 var largestNumber = function(nums) { 6 var str = nums.join().replace(/\,/g, ‘‘); 7 var arr = []; 8 for(var i = 0; i < str.length; i++) { 9 arr.push(str.charAt(i)); 10 } 11 nums = arr.sort(function(a, b) { 12 return b -a; 13 }) 14 return nums.join().replace(/\,/g, ‘‘); 15 };
标签:
原文地址:http://www.cnblogs.com/maduar/p/5947625.html