Problem · Array
Largest Number
Learn this problemProblem statement
Given an array of nonnegative integers nums, arrange them so that their decimal representations form the largest possible number.
Return the result as a string. If every number is zero, return "0".
Function
largestNumber(nums: int[]) → StringExamples
Example 1
nums = [10,2]return = "210"Placing 2 before 10 produces the larger concatenation.
Example 2
nums = [3,30,34,5,9]return = "9534330"Ordering by pairwise concatenation places 9, 5, 34, 3, then 30.
Constraints
1 <= nums.length <= 1000 <= nums[i] <= 1000000000