题解 | #数字在升序数组中出现的次数#
把数组排成最小的数
http://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993
思路:类似于插入排序,每增加一个元素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)