Package com.abuge;
/** * Face Test 33: Put the array in the smallest number * Enter a positive integer array, put all the numbers in the array into a number, printing to be able to stitch out the smallest of all numbers.
* For example, the input array {3, 32, 321} will print the smallest number of three digits * thinking: * 1, the conversion of integer number to string, can solve the problem of invisible large number * 2, the development of new rules/import java.util.Arrays;
Import Java.util.Comparator;
Class Mycomprator implements comparator<string> {String result1 = null;
String result2 = null;
@Override public int Compare (string str1, String str2) {result1 = str1+ str2;
RESULT2 = str2 + str1;
Return Result1.compareto (RESULT2); } public class Getminnum {public static String Getminnum (int[] A, int len) {if (a = = NULL | | | len <= 0) Retu
RN null;
string[] tmp = new String[len];
Converts an array to a string for (int i = 0; i < len; i++) {Tmp[i] = string.valueof (a[i));
Arrays.sort (TMP, New Mycomprator ()) sorted by the new rule;
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < len; i++) {sb.append (tmp[i]);
return sb.tostring (); public static void Main (string[] args) {int[] a = {456, 3, 1};
int len = a.length;
System.out.println (Getminnum (A, Len));
}
}