leetcode179.最大数(学习了java实现Comparator接口)
String.valueof,Inteager.parseInt
class Solution { public String largestNumber(int[] nums) { Integer a[] = new Integer [nums.length]; for(int i=0;i<nums.length;i++){ a[i]=nums[i]; } Arrays.sort(a,new Comparator<Integer>(){ @Override public int compare(Integer x, Integer y) { long sx = 10, sy = 10; while (sx <= x) { sx *= 10; } while (sy <= y) { sy *= 10; } return (int) (-sy * x - y + sx * y + x); } }); if(a[0]==0) return "0"; String s=""; for(int i=0;i<a.length;i++){ s+=String.valueOf(a[i]); } return s; } }