179. Largest Number
179. Largest Number主要考的自定义函数?
class Solution(object):
def largestNumber(self, nums):
"""
:type nums: List[int]
:rtype: str
"""
def comp(a, b):
if a + b > b + a:
return 1
elif a + b < b + a:
return -1
else:
return 0
nums = [str(num) for num in nums]
nums.sort(comp, reverse=True)
ans = ''.join(nums)
return '0' if int(ans) == 0 else ans
网友评论