利用java的API对数组中的数字组合进行排序
java 代码
class Solution {
public String printMinNumber(int[] nums) {
IntStream stream = Arrays.stream(nums);
Stream<Integer> integerStream = stream.boxed();
Integer[] integers = integerStream.toArray(Integer[]::new);
return mysort(integers);
}
private String mysort(Integer[] arr)
{
Arrays.sort(arr, new Comparator<Integer>(){
public int compare(Integer a1, Integer a2)
{
String s1 = a1 + "" + a2;
String s2 = a2 + "" + a1;
return s1.compareTo(s2);
}
});
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < arr.length; i++) sb.append(arr[i]);
return sb.toString();
}
}