179. 最大数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public String largestNumber(int[] nums) {
Queue<Integer> queue = new PriorityQueue<>((o1,o2)->{
String num1 = "" + o1 + o2;
String num2 = "" + o2 + o1;
return num2.compareTo(num1);
});

for(int i = 0; i < nums.length; i++){
queue.offer(nums[i]);
}

StringBuffer buffer = new StringBuffer();
while(!queue.isEmpty()){
buffer.append(queue.poll());
}
String ans = buffer.toString();
if(ans.startsWith("0")){
return "0";
}

return ans;
}
}