Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very large, so you need to return a string instead of an integer. 思路:比较两个数连接后的大小进行排序。 Runtime: 125 ms beats 88.37%
1
2
3
4
5
6
7
8
publicstatic String (int[] nums){
String[] s = new String[nums.length];
for (int i = 0; i < nums.length; i++) s[i] = String.valueOf(nums[i]);
Arrays.sort(s, (b, a) -> (a.concat(b).compareTo(b.concat(a))));
近期评论