-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution179.java
More file actions
35 lines (32 loc) · 1.05 KB
/
Copy pathSolution179.java
File metadata and controls
35 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
public class Solution179 {
private static int[] num = {432,43243};
public static String largestNumber(int[] nums) {
List<Integer> tmp = new LinkedList<>();
for (int i : nums){
tmp.add(i);
}
tmp.sort(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
if (Long.valueOf(String.valueOf(o1)+String.valueOf(o2)) > Long.valueOf(String.valueOf(o2)+String.valueOf(o1))){
return -1;
}
else return 1;
}
});
StringBuilder sb = new StringBuilder();
for (int i : tmp){
sb.append(i);
}
int i = 0;
while (i < nums.length && nums[i] == 0) i++;
if (i == nums.length) return "0";
return sb.toString();
}
public static void main(String[] args) {
System.out.println(largestNumber(num));
}
}