Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.

Since the result may be very large, so you need to return a string instead of an integer.

&nbsp;
Example 1:

Input: nums = [10,2]
Output: "210"


Example 2:

Input: nums = [3,30,34,5,9]
Output: "9534330"


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 100
	0 &lt;= nums[i] &lt;= 109


from functools import cmp_to_key
class Solution:
    def largestNumber(self, nums: List[int]) -> str:
        nums = list(map(str, nums))
        nums = reversed(sorted(nums, key = cmp_to_key(lambda x, y: -1 if int(x+y) < int(y+x) else ( 1 if int(x+y) > int(y+x) else 0))))
        res = "".join(nums)
        return res if int(res) else "0"
class Solution {
    public String largestNumber(int[] nums) {
        String[] arr=new String[nums.length];
        for(int i=0;i<nums.length;i++){
            arr[i]=Integer.toString(nums[i]);
        }
        Arrays.sort(arr,(a,b)->(b+a).compareTo(a+b));
        if(arr[0].equals("0")) return "0";
        StringBuilder builder=new StringBuilder();
        for(String item:arr){
            builder.append(item);
        }
        return builder.toString();
    }
}
class Solution {
public:
    string largestNumber(vector<int>& nums) {
        sort(nums.begin(),nums.end(),[&](int a,int b){
            string order1 = to_string(a)+to_string(b);
            string order2 = to_string(b)+to_string(a);
            return order1>order2;
        });
        
        string ans = "";
        for(int i = 0;i<nums.size();i++){
            if(nums[0]==0) return "0";
            ans += to_string(nums[i]);
        }
        return ans;
    }
};
var largestNumber = function(nums) {
    var arr=[]
    nums.forEach((item)=>{
        arr.push(item.toString());
    })
    arr.sort((a,b)=>(b+a).localeCompare(a+b));
    var ret=""
    if(arr[0]=="0") return "0";
    arr.forEach((item)=>{
        ret+=item;
    })
    return ret;
};
Largest Number