通过比较字符串来得到答案
把数组排成最小的数
http://www.nowcoder.com/questionTerminal/8fecd3f8ba334add803bf2a06af1b993
public String PrintMinNumber(int [] numbers) { ArrayList<char[]> list = new ArrayList<>(); String result = ""; for (int i=0;i<numbers.length;i++){ String s = ""+numbers[i]; list.add(s.toCharArray()); } list.sort(new Comparator<char[]>() { @Override public int compare(char[] o1, char[] o2) { int minlength = o1.length<o2.length?o1.length:o2.length; for(int i=0;i<minlength;i++){ if (o1[i]>o2[i]) return 1; else if (o1[i]<o2[i]) return -1; } if (o1.length==o2.length) return 0; if (o1.length<o2.length) { while(minlength<o2.length && o1[0]==o2[minlength]) minlength++; if (minlength<o2.length && o1[0]<o2[minlength]) return -1; return 1; }else { while(minlength<o1.length && o1[0]==o1[minlength]) minlength++; if (minlength<o1.length && o2[0]<o1[minlength]) return 1; return -1; } } }); for (int i=0;i<numbers.length;i++) { result+=String.valueOf(list.get(i)); System.out.println(Arrays.toString(list.get(i))); } return result; }