Title Descriptionenter an array of positive integers, combine all the numbers in the array into a number, and print the smallest of all the numbers that can be stitched together. For example, enter the array {3,32,321}, then print out the minimum number that these three numbers can be ranked as 321323. problem-solving ideas: the subject of MN and NM, which is how small line1) First copy each number into the strname in the form of a string2) Sort the call to it. Sort by the Compare rules we designed to compare3) Put the sorted array into the result and return the result
1 BOOLCompareConst string&st1,Const string&st2)2 {3 stringS1 = St1 +St2;4 stringS2 = St2 +St1;5 returnS1 <S2;6 }7 classSolution {8 Public:9 Const intG_maxnumberlength=Ten;Ten stringPrintminnumber (vector<int>numbers) { One stringresult; A intLength =numbers.size (); - if(Length <=0) - returnresult; the Char* * strnumbers=New Char*[length]; - for(intI=0; i<length;i++) - { -strnumbers[i]=New Char[g_maxnumberlength+1]; +sprintf (Strnumbers[i],"%d", Numbers[i]); - } +Sort (strnumbers,strnumbers+length,compare); A for(intI=0; i<length;i++) at result.append (Strnumbers[i]); - - for(intI=0; i<length;i++) - Delete[] strnumbers[i]; - Delete[] strnumbers; - returnresult; in } -};
32, the sword refers to offer--the array to the smallest number