Largest Number
Arrangement/Sorting
Last updated
Was this helpful?
Arrangement/Sorting
Last updated
Was this helpful?
Given a list of non-negative integers nums
, arrange them such that they form the largest number.
Note: The result may be very large, so you need to return a string instead of an integer.
For example:
The idea here is to use a "comparison based" sorting algorithm
Given two numbers A and B, we compare two numbers AB (B appended at the end of A) and BA (A appended at the end of B). If AB is larger, then this means in the output, A should come before B, else if AB isn't larger, then B should come before A.
Example: let A and B be 542 and 60. To compare A and B, we compare 54260 and 60542. Since 60542 is greater than 54260, we put B first.
We are comparing two concatenated elements to each other to see if or
We are arranging the elements based on comparing their different concatenations
Time:
Space: