Largest Number
Medium · greedy
You are given a list of non-negative integers nums. Write them one after another, in any order you choose, to make one long number. For example, writing 7 then 31 makes 731.
Return the largest number you can make, as a string, because it may be far too big for an integer type.
Use every number exactly once. If the largest result is made only of zeros, return "0" rather than a string such as "000".
Examples
Example 1
Input: nums = [12, 9, 121]
Output: "912121"
9 goes first. Between 12 and 121, writing 12 then 121 gives 12121, which beats 12112.
Example 2
Input: nums = [0, 0]
Output: "0"
Every order gives zeros, so the answer is a single 0.
Example 3
Input: nums = [20, 2, 200]
Output: "220200"
Writing 2, then 20, then 200 gives 220200, the biggest of the six orders.
Constraints
- 1 <= len(nums) <= 1000
- 0 <= nums[i] <= 10^9