我也用的比较器,AC 了 public static void bilibiliFun2(List list) {
list.sort(new Com());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i));
}
System.out.println(sb.toString());
}
static class Com implements Comparator<Integer> {
@Override
public int compare(Integer o1, Integer o2) {
int a = Integer.valueOf(String.valueOf(o1).charAt(0));
int b = Integer.valueOf(String.valueOf(o2).charAt(0));
int i = 1;
while (a == b) {
if (String.valueOf(o1).length() > i && String.valueOf(o2).length() > i) {
a = Integer.valueOf(String.valueOf(o1).charAt(i));
b = Integer.valueOf(String.valueOf(o2).charAt(i));
} else {
if (String.valueOf(o1).length() < String.valueOf(o2).length()
&& Integer.valueOf(String.valueOf(o1).charAt(0)) < Integer.valueOf(String.valueOf(o2).charAt(String.valueOf(o2).length() - 1))) {
return -1;
} else if (String.valueOf(o1).length() > String.valueOf(o2).length()
&& Integer.valueOf(String.valueOf(o2).charAt(0)) > Integer.valueOf(String.valueOf(o1).charAt(String.valueOf(o1).length() - 1))) {
return -1;
} else {
return 1;
}
}
i++;
}
return a - b;
}
}