[关闭]
@Scrazy 2017-04-12T10:00:27.000000Z 字数 343 阅读 808

使数组中的数 组成的数值最小

python 算法


eg:array = [12, 3, 4, 5]
12345 是其最小值

  1. # coding=utf-8
  2. import functools
  3. class Solution:
  4. def print_min_number(self, numbers):
  5. cmp = lambda x, y: int(str(x)+str(y))- int(str(y)+str(x))
  6. numbers.sort(key=functools.cmp_to_key(cmp))
  7. result = ''.join(map(str, numbers))
  8. return result
  9. s = Solution()
  10. numbers = [3, 5, 2, 4, 10, 34, 2345, 9876]
  11. print(s.print_min_number(numbers))
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注