//方案一:java
public class Solution {app
public String PrintMinNumber(int [] numbers) { int len=numbers.length; String a[]=new String[len]; for(int i=0;i<len;i++){ a[i]=String.valueOf(numbers[i]); } String aa=null; String bb=null; String temp=null; for(int i=0;i<len-1;i++) for(int j=0;j<len-i-1;j++){ aa=a[j]+a[j+1]; bb=a[j+1]+a[j]; if(aa.compareTo(bb)>0) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } StringBuffer s=new StringBuffer(); for(int i=0;i<len;i++) s.append(a[i]); return s.toString(); }
}code
//方案二排序
import java.util.ArrayList;io
import java.util.*;class
public class Solution {import
public String PrintMinNumber(int [] numbers) { int len=numbers.length; ArrayList<String> list = new ArrayList<String>(); for(int i=0;i<len;i++) list.add(String.valueOf(numbers[i])); Collections.sort(list,new Comparator<String>(){ public int compare(String s1,String s2){ String temp1=s1+s2; String temp2=s2+s1; return temp1.compareTo(temp2); } }); StringBuffer s = new StringBuffer(); for(String i:list) s.append(i); return s.toString(); }
}List
寫個冒泡排序更容易理解些im