Title: the integer array containing n elements, the n elements are re-assembled to find the smallest number, such as (321,3,32,) the minimum number is 321323
Topic Analysis:
Fills all the elements in the array into equal numbers, fills the number with the last digit, as shown in this case, after the padding is {321,333,322}, and then sorts by size,
After sorting, the numbers are removed and the number after stitching is the minimum number, which is {321,322,333} after sorting, minus the padding number {321,32,3}, which is 321323
Python implementation
defMergeminvalue (LST):#generating a list of stringsLST =list (map (str,lst))#get the longest number lengthm = Len (max (lst,key=len)) #get a new list based on the original integerNewList = [(i,i+i[-1]* (M-len (i))) forIinchLST]#sort the padded numeric charactersNewlist.sort (key=LambdaItem:item[1]) #stitching the original numbersresult ="'. Join ((item[0) forIteminchnewlist)) returnInt (Result)
Test examples:
LST = [321,3,31,38,93]print(Mergeminvalue (LST))
Test output
3132133893
Data reference: Python Cottage
Python solve array to re-combine to find the minimum value (Youku)