标签:des tostring pen value 最小数 util new return ++
对数值排序,每两个比较 连在一起 小的在前面;
import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; public class Solution { public String PrintMinNumber(int [] numbers) { if(numbers ==null ||numbers.length<=0){ return new String(); } Integer[] nums = new Integer[numbers.length]; for(int i=0;i<numbers.length;i++){ nums[i] = numbers[i]; } Arrays.sort(nums,new Comparator<Integer>(){ public int compare(Integer o1,Integer o2){ int val1 = Integer.valueOf(String.valueOf(o1)+String.valueOf(o2)); int val2 = Integer.valueOf(String.valueOf(o2)+String.valueOf(o1)); return val1-val2; } }); StringBuilder re =new StringBuilder(); for(int i =0;i<nums.length;i++){ re.append(nums[i]); } return re.toString(); } }
标签:des tostring pen value 最小数 util new return ++
原文地址:https://www.cnblogs.com/zhacai/p/11279133.html