leetcode那些让人长见识的代码

    xiaoxiao2021-03-25  173

    179. Largest Number

    @xcv58 :

    def largestNumber(self, num): num = [str(x) for x in num] num.sort(cmp=lambda x, y: cmp(y+x, x+y)) return ''.join(num).lstrip('0') or '0' @ahmed7: def largestNumber(self, num): comp=lambda a,b:1 if a+b>b+a else -1 if a+b<b+a else 0 num=map(str,num) num.sort(cmp=comp,reverse=True) return str(int("".join(num)))

    转载请注明原文地址: https://ju.6miu.com/read-7314.html

    最新回复(0)