package leetcode; public class demo_173 { public String largestNumber(int[] nums) { String str=""; String[] strnum=new String[nums.length]; int flag=0; for(int i=0;i<nums.length;i++) { if(nums[i]!=0) {flag=1;} strnum[i]=String.valueOf(nums[i]); } if(flag==0) {return "0";} //比较字符串(int)x+y与(int)y+x的大小 for(int i=0;i<nums.length-1;i++) { for(int j=0;j<nums.length-i-1;j++) { if(Long.valueOf(strnum[j]+strnum[j+1])<Long.valueOf(strnum[j+1]+strnum[j])) { String s=strnum[j]; strnum[j]=strnum[j+1]; strnum[j+1]=s; } } } for(String s:strnum) { str=str+s; } System.out.println(str); return str; } public static void main(String[] args) { // TODO Auto-generated method stub demo_173 d173=new demo_173(); int[] nums= {0,0}; d173.largestNumber(nums); } }