My 4 lines python solution


  • 1
    S
    class Solution:
        def largestNumber(self, nums):
            st =  "".join(sorted(map(str, nums), cmp = lambda x, y: int(y + x) - int(x + y)))
            return  st if st[0] != "0" else "0"

  • 0

    It's so brilliant that you use 'cmp = lambda x, y: int(y + x) - int(x + y)'! I used sorted func but found that '30'>'3', and I have no idea how to change it. your solution just helpd me.Thx for sharing!


Log in to reply
 

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