179. Largest Number(sort中比较规则的用法)
Posted bernieloveslife
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了179. Largest Number(sort中比较规则的用法)相关的知识,希望对你有一定的参考价值。
Given a list of non negative integers, arrange them such that they form the largest number.
Example 1:
Input: [10,2]
Output: "210"
Example 2:
Input: [3,30,34,5,9]
Output: "9534330"
Note: The result may be very large, so you need to return a string instead of an integer.
class compare(str):
def __lt__(a, b):
return a + b >b + a
class Solution(object):
def largestNumber(self, nums):
"""
:type nums: List[int]
:rtype: str
"""
res = ‘‘.join(sorted(map(str,nums),key = compare))
return ‘0‘ if res[0]==‘0‘ else res
konw how to use compare and map
以上是关于179. Largest Number(sort中比较规则的用法)的主要内容,如果未能解决你的问题,请参考以下文章
leetcode_num179_Largest Number
LeetCode 179. Largest Number (最大数)