直接用暴力法列出所有排列然后选最小没想到能过。
public String PrintMinNumber(int [] numbers) { if(numbers==null||numbers.length==0)return ""; long min = Long.MAX_VALUE; ArrayList<String> help = help(numbers, 0); for (String s : help) { long i = Long.valueOf(s); if(i<min) min =i; } return String.valueOf(min); } private ArrayList<String> help(int[] nums, int i) { ArrayList<String> res = new ArrayList<>(); if(i==nums.length-1){ res.add(String.valueOf(nums[i])); return res; } for (int j = i++; j <nums.length ; j++) { int temp = nums[j]; nums[j]=nums[i-1]; nums[i-1]=temp; ArrayList<String> newRes = help(nums, i); //处理结果 for (int k = 0; k < newRes.size(); k++) { res.add(String.valueOf(nums[i-1])+newRes.get(k)); } temp = nums[j]; nums[j]=nums[i-1]; nums[i-1]=temp; } return res; }