import java.util.*; public class Solution { /** * 最大数 * @param nums int整型一维数组 * @return string字符串 */ public String solve (int[] nums) { // write code here String[] ss = new String[nums.length]; StringBuilder sb = new StringBuilder(); for(int i = 0; i < nums.length; i++) { ss[i] = String.valueOf(nums[i]); } Arrays.sort(ss, (String s1,String s2) -> { return Integer.valueOf(s1 + s2) - Integer.valueOf(s2+s1); } // new Comparator<String>(){ // @Override // public int compare(String s1,String s2){ // return Integer.valueOf(s1 + s2) - Integer.valueOf(s2+s1); // } // } ); for(int i = nums.length-1; i >= 0; i--) { sb.append(ss[i]); } String res = sb.toString(); return (res.charAt(0) == '0') ? "0" : res; } }