import java.util.ArrayList; /** 我的思路和别人不太一样。 主要是在比大小的逻辑。 例如{3,32,321} 3和32,我想的是用33和32比。(((代码复杂好多,,, */ public class Solution { public String PrintMinNumber(int [] numbers) { for (int i = 0; i < numbers.length; i++) { for (int j = i + 1; j < numbers.length; j++) { if(compareBig(numbers[i], numbers[j])){ int temp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = temp; } } } StringBuffer sb = new StringBuffer(); for (int num : numbers) { sb.append(num); } return sb.toString(); } /** x是否比y大。 */ public boolean compareBig(int x, int y){ String strX = String.valueOf(x); String strY = String.valueOf(y); int diff = strX.length() - strY.length(); if(diff == 0){ return x > y; } else if(diff > 0) { String newStrY = strY; for (int i = 0; i < diff; i++) { newStrY += strY.substring(0, 1); } int newY = Integer.valueOf(newStrY); return x > newY; } else { String newStrX = strX; for (int i = 0; i < -diff; i++) { newStrX += strX.substring(0, 1); } int newx = Integer.valueOf(newStrX); return newx > y; } } }