![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/79bcf934893c252ba12bf902d4a5de5c.png)
代码演示:
package swordfingeroffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class InterviewQuestion45 {
public String printMinNumber(int[] numbers) {
if (null == numbers || 0 == numbers.length) {
return null;
}
List<String> list = new ArrayList<>();
for (int num : numbers) {
list.add(String.valueOf(num));
}
Collections.sort(list, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
String s1 = o1 + o2;
String s2 = o2 + o1;
return s1.compareTo(s2);
}
});
StringBuilder stringBuilder = new StringBuilder();
for (String str : list) {
stringBuilder.append(str);
}
return stringBuilder.toString();
}
}