#main idea: change the default implementation for comparison and sort in descending order.
class Solution:
    def largestNumber(self, nums: List[int]) -> str:
        # time O(NlgN) space O(N)
        comp = lambda a,b:1 if a+b > b+a else -1 if a+b < b+a else 0
        _nums = list(map(str,nums)) # here add a list() is to convert map object into list type, for the intention to sort below; because we can not sort inplace. but if using sorted() will work without list() to pre process  
        _nums.sort(reverse=True,key=functools.cmp_to_key(comp))
        # str int double typle conversion is to handle the case if input nums is a list of [0,0,0], where we can only return '0'
        return str(int(''.join(_nums)))
class Comp(str):
    def __lt__(n1,n2):
        if n1 + n2 > n2 + n1:
            return 1
        else:
            return 0
class Solution:
    def largestNumber(self, nums: List[int]) -> str:
        # time O(NlgN) space O(N)
        nums = [str(num) for num in nums]
        nums = sorted(nums,key=Comp)
        res = ''.join(nums)
        return res if res[0]!= '0' else '0'