leetcode那些让人长见识的代码

来源:互联网 发布:js单引号的转义字符串 编辑:程序博客网 时间:2024/04/30 18:44

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'
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)))

0 0
原创粉丝点击