179. Largest Number
Problem description:
Given a list of non negative integers, arrange them such that they form the largest number.
Example 1:1
2Input: [10,2]
Output: "210"
Example 2:1
2Input: [3,30,34,5,9]
Output: "9534330"
Note: The result may be very large, so you need to return a string instead of an integer.
Solution:
First, sort the array based on the combination of two integer.
After sorting, we can use the array to create result string.
For example:
Input: [10,2]
“2”+”10”-> 210
“10”+”2”-> 102
1 | class Solution { |