Largest Number
Arrangement/Sorting
Problem
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:
Though Process
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.
Solution
Key Facts
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 Complexity
Time:
Space:
Last updated