class Comparator(str):  # python inheritance from str
    def __lt__(x, y):  # override compare method to sort desc
        return x + y > y + x


class Solution:
    def largestNumber(self, nums: List[int]) -> str:
        if len(nums) == 1:
            return str(nums[0])

        if all(t == 0 for t in
               nums):  # if all zeroes then sorting will retain all zeroes => "00000". Answer expects "0" instead.
            return "0"

        nums_as_str = list(map(lambda x: str(x), nums))  # transform values to str
        nums_as_str.sort(key=Comparator)

        return "".join(nums_as_str)