题解 | #把数组排成最小的数 贪心算法#
把数组排成最小的数
http://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993
import java.util.*;
public class Solution {
public String PrintMinNumber(int [] numbers) {
if(numbers.length == 0){return "";}
String[] str1 = new String[numbers.length];
for(int i = 0; i < numbers.length; i++){
str1[i] = numbers[i] + "";
}
//贪心算法:相邻两者的字典序最小
Arrays.sort(str1, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return (o1 + o2).compareTo(o2 + o1);
}
});
String res = new String();
for (String tmp : str1) {
res += tmp;
}
return res;
}
}