package pers.lyt.java;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class Offer45_SortArrayForMinNumber {
public String PrintMinNumber(int[] numbers) {
if (numbers == null || numbers.length <= 0)
return "";
ArrayList<String> list = new ArrayList<String>();
for (int number : numbers)
list.add(String.valueOf(number));
Collections.sort(list, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
String a = s1 + s2;
String b = s2 + s1;
return a.compareTo(b);
}
});
StringBuilder sb = new StringBuilder();
for (String str : list)
sb.append(str);
return sb.charAt(0) == '0' ? "0" : sb.toString();
}
public static void main(String[] args) {
Offer45_SortArrayForMinNumber demo = new Offer45_SortArrayForMinNumber();
int[] arr = new int[]{3,30,34,5,9};
String printMinNumber = demo.PrintMinNumber(arr);
System.out.println(printMinNumber);
}
}