题解 | #把数组排成最小的数#
把数组排成最小的数
http://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993
import functools
class Solution:
def PrintMinNumber(self , numbers: List[int]) -> str:
# write code here
if not numbers: return ''
length=len(numbers)
if length==1: return str(numbers[0])
def __mysort(x,y):
if (x + y) > (y + x):return 1
else: return -1
li=[str(i) for i in numbers]
li.sort(key=functools.cmp_to_key(__mysort))
return ''.join(li)
题解-数据结构与算法 文章被收录于专栏
小菜鸟的题解