Title Description
Enter 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.
Convert a number to a string and then quickly sort the string
classSolution { Public:stringPrintminnumber ( vector<int>Numbers) {stringR vector<string>Sr for(intI=0; I<numbers.size (); i++) {Sr.push_back (numbertostring (numbers[i])); } sort (Sr.begin (), sr.end (), compare); for(intI=0; I<sr.size (); i++) {r + = Sr[i]; }returnR }stringNumbertostring (intN) {return(n>9? numbertostring (n/Ten):"")+Char(n%Ten+' 0 '); }Static BOOLCompareConst string& A,Const string& B) {returna+b<=b+a; } };
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Point of Offer" the smallest number of arrays