You will love me by seeing this Python solution, beating 100%


  • 0
    Y
    class Solution:
        # @param {integer[]} nums
        # @return {string}
        def largestNumber(self, nums):
            def comparator(a, b):
                a = str(a)
                b = str(b)
                s1 = a + b
                s2 = b + a
                if s1 > s2:
                    return -1
                elif s1 < s2:
                    return 1
                else:
                    return 0
            
            
            nums = sorted(nums, cmp = comparator)
            res = "".join(map(str, nums))
            
            for i in xrange(len(res)):
                if res[i] != '0':
                    break
            
            return res[i:]
            
    

Log in to reply
 

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