题意:输入一个非负数组,把数组中所有数字拼接成一个数,打印能拼接处的所有数字中最小的一个。
示例 1:
输入: [10,2]
输出: "102"
示例 2:
输入: [3,30,34,5,9]
输出: "3033459"
public class Solution {public static void main(String[] args) {Integer[] num&#61;new Integer[nums.length];int index&#61;0;for(int n:nums){num[index&#43;&#43;]&#61;num;}Arrays.sort(num,new Comparator<Integer>(){&#64;Overridepublic int compare(Integer o1, Integer o2) {return (o2.toString()&#43;o1.toString()).compareTo(o1.toString()&#43;o2.toString());}});StringBuilder s&#61;new StringBuilder();for(Integer n:num){s.append(n);}System.out.println(s.toString());}
}