标签:on() ring input graph int ini use elf graphic
import functools class Solution: # @param {integer[]} nums # @return {string} def largestNumber(self, nums): def comparator(x, y): # inputs are string representations of non-negative ints if x+y > y+x: # no need to convert to int because x+y and y+x are same length return -1 # so lexicographic string sort behaves like numeric sort else: return 1 nums = list(map(str, nums)) # convert to strings nums.sort(key=functools.cmp_to_key(comparator)) return nums ls=[1,6,4,9,2,8] x=Solution() print(x.largestNumber(ls))
输出
[‘9‘, ‘8‘, ‘6‘, ‘4‘, ‘2‘, ‘1‘] [Program finished]
标签:on() ring input graph int ini use elf graphic
原文地址:https://www.cnblogs.com/sea-stream/p/10619450.html