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.
Import java.util.ArrayList;
Import Java.util.Comparator;
Import java.util.Collections;
Import java.util.*;
public class Solution {
Public String printminnumber (int [] numbers) {
String[] Str=new string[numbers.length];
StringBuilder sb=new StringBuilder ();
if (numbers.length<=0| | Numbers==null) return "";
for (int i=0;i<numbers.length;i++) {
Str[i]=string.valueof (Numbers[i]);
}
Arrays.sort (str,new comparator<string> () {
@Override//rewrite
public int Compare (String str1,string str2) {
String c1=str1+str2;
String c2=str2+str1;
return C1.compareto (C2);
}
});
for (int j=0;j<numbers.length;j++) {
Sb.append (Str[j]);
}
return sb.tostring ();
}
}
To rank the array into the smallest number