思路:类似于插入排序,每增加一个元素i,判断i与i-0全部数据所能组成的最小数,依次交换
class Solution:
def PrintMinNumber(self , numbers: List[int]) -> str:
# write code here
if len(numbers) == 0:
return ""
for i in range(1, len(numbers)):
j = i - 1
while j >= 0:
if int(str(numbers[j]) + str(numbers[j+1])) > int(str(numbers[j+1]) + str(numbers[j])):
numbers[j+1], numbers[j] = numbers[j], numbers[j+1]
j -= 1
result = [str(i) for i in numbers]
return "".join(result)