import java.util.*; public class Solution { //自定义排序规则:思想就是让任意两个数字组成的数都是较小的哪一种情况 class Myconparator implements Comparator<Integer> { public int compare(Integer n1 , Integer n2) { long l1 = Long.parseLong(n1+""+n2) ; long l2 = Long.parseLong(n2+""+n1) ; if(l1 == l2) { return 0 ; } else if(l1 > l2) { return 1 ; } else { return -1 ; } } } //快排(也可以用Arrays.sort() , 单纯练习一下快排) public void sort(int[] numbers , int start , int end , Myconparator cmp) { if(start >= end) { return ; } int i = start ; int j = end ; int temp = numbers[start] ; while(i < j) { while(i < j && cmp.compare(numbers[j],temp) > 0) { j-- ; } if(i < j) { numbers[i] = numbers[j] ; i++ ; } while(i < j && cmp.compare(numbers[i],temp) < 0) { i++ ; } if(i < j) { numbers[j] = numbers[i] ; j-- ; } } numbers[i] = temp ; sort(numbers , start , i-1,cmp) ; sort(numbers , i+1 , end , cmp) ; } public String PrintMinNumber(int [] numbers) { sort(numbers , 0 , numbers.length-1 , new Myconparator()) ; StringBuilder sb = new StringBuilder() ; for(int n : numbers) { sb.append(String.valueOf(n)) ; } return sb.toString() ; } }