#
# 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。
#
# 示例 1:
# 输入: [10,2]
# 输出: "102"
#
# 示例2:
# 输入: [3,30,34,5,9]
# 输出: "3033459"
# #1
# class Solution:
# def minNumber(self, nums):
# nums_str=[str(i) for i in nums]#数组数字转字符串
# for i in range(len(nums)-1):
# for j in range(i+1,len(nums)):
# if nums_str[i]+nums_str[j]>nums_str[j]+nums_str[i]:#字符串拼接比较大小
# nums_str[i],nums_str[j]=nums_str[j],nums_str[i]#根据拼接比较结果,小数在前大数在后
# output=''.join(nums_str)#拼接字符串
# return output
# # nums=[3,30,34,5,9]
# nums=[58,7,3,30,34]
# s=Solution()
# output=s.minNumber(nums)
# print(output)
#
#
# #2
# class cmpSmaller(str):
# def __lt__(self, y):#富比较方法
# # print('self=',self)
# # print('y=',y)
# return self + y < y + self # 字符串拼接比较(两两比较)
# # 按由小到大来排列
# class Solution:
# def minNumber(self, nums):
# res=sorted(map(str, nums),key=cmpSmaller)
# smallest = ''.join(res)
# return smallest
# nums=[58,7,3,30,34]
# s=Solution()
# output=s.minNumber(nums)
# print(output)
#
#
# #3
# import itertools
# def fun1(a):
# # itertools.permutations(iterable, r)
# # 第一个参数为可迭代对象,第二个参数为参与排列的元素的个数,r的默认值为可迭代对象的长度,即全排列
# # 返回一个元素类型为元组的迭代器
# b = []
# full_permutation = list(itertools.permutations(a,len(a)))
# # print(full_permutation)
# for i in full_permutation:
# b.append(''.join([str(n) for n in i]))
# return sorted(b)[0]
# a = [3,31,34,5,9]
# res = fun1(a)
# print(res)
#
#
# #4
# import functools
# def minNumber(nums):
# def sort_rule(x, y):
# a, b = x + y, y + x
# if a > b:
# return 1
# elif a < b:
# return -1
# else:
# return 0
# strs = [str(num) for num in nums]
# strs.sort(key=functools.cmp_to_key(sort_rule),reverse=False)
# return ''.join(strs)
# print(minNumber([3,31,34,5,112]))