199. Biggest Joined Number
You are given a list of non-negative integers nums. Write them one after another, in any order you like, without separators, so the digits form one long number. For instance, [2, 10] can become 210 or 102.
Return the arrangement that gives the numerically largest result. The result can be far too big for any integer type, so return it as a string. If every number is zero, return the single character "0" rather than a string of several zeros.
Example 1
- Input:
- nums = [12,121,98,9]
- Output:
- "99812121"
- Explanation:
The best order is 9, 98, 12, 121: 9 98 12 121 gives 99812121, because 12 followed by 121 beats 121 followed by 12.
Example 2
- Input:
- nums = [0,0,0]
- Output:
- "0"
- Explanation:
Every arrangement is zeros, so the answer is the single digit 0.
Example 3
- Input:
- nums = [7]
- Output:
- "7"
- Explanation:
One number can only be itself.
Constraints
1 ≤ nums.length ≤ 2 × 104
0 ≤ nums[i] ≤ 109
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
- Time per case
- Python 2,000 msC++ 500 msJava 1,000 msJavaScript 1,000 msTypeScript 1,000 ms
Expected complexity
- Time
- O(n log n × L)
- Space
- O(n × L)