Python using cmp function with sort


  • 1
    A
    def largestNumber(self, nums):
        if not nums:
            return 0
            
        def compare(n1, n2):
            if int(n1+n2)>int(n2+n1):
                return -1
            else:
                return 1
            
        nums = map(str, nums)
        nums.sort(cmp = compare)
        return str(int(''.join(nums)))

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.