1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public class Solution { public String PrintMinNumber(int [] numbers) { if(numbers.length==0){ return ""; } String str = ""; for (int i = 0;i< numbers.length-1;i++){ for (int j = 0;j< numbers.length-1-i;j++){ int numberA = numbers[j]; int numberB = numbers[j+1]; String numberAStr = numberA+""; String numberBStr = numberB+""; if(numberAStr.length()<numberBStr.length()){ numberAStr = numberB+""; numberBStr = numberA+""; } int b = new Integer(numberBStr).intValue(); for(int k = 0;k <= numberAStr.length()-numberBStr.length();k++){ int a = new Integer(numberAStr.substring(k,k+numberBStr.length())).intValue(); if(a>b){ numbers[j] = b; numbers[j+1] = new Integer(numberAStr).intValue(); break; }else if(a<b){ numbers[j] = new Integer(numberAStr).intValue(); numbers[j+1] = b; break; } } if(j == numbers.length-2-i ){ str = numbers[j+1] + str; } } } str = numbers[0]+str; return str; } }
|