1 line Python

  • 0

    Sort the array by two different concatenation situations first, then remember to check if nums is empty or every elements in nums are 0.

    class Solution:
        # @param {integer[]} nums
        # @return {string}
        def largestNumber(self, nums):
            return "".join(sorted(map(str, nums), cmp = lambda x, y: cmp(y+x, x+y))) \
                   if nums and set(nums) != {0} else "0"

Log in to reply

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