把数组排成最小的数 牛客网 剑指Offer

  • 题目描述
  • 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。
from functools import cmp_to_key
class Solution:
    def PrintMinNumber(self, numbers):
        if numbers == None or len(numbers) <= 0:
            return ''
        strList = []
        for i in numbers:
            strList.append(str(i))
        key = cmp_to_key(lambda x, y: int(x+y)-int(y+x))
        strList.sort(key=key)
        return ''.join(strList)

 

相关文章:

  • 2022-12-23
  • 2022-03-02
  • 2021-10-26
  • 2021-12-18
  • 2021-08-07
  • 2022-12-23
  • 2021-12-15
  • 2021-09-15
猜你喜欢
  • 2021-07-23
  • 2022-02-22
  • 2022-02-25
  • 2022-02-26
  • 2021-07-27
  • 2021-08-07
相关资源
相似解决方案