public class Solution implements Comparator<Integer> {
public String largestNumber(final List<Integer> A) {
List<Integer> B = A;
StringBuilder str = new StringBuilder();
Collections.sort(B,this);
for (int i=B.size()-1; i >= 0; i--) {
str = str.append(B.get(i));
}
return str.toString();
}
public int compare(Integer X, Integer Y) {
String XY = Integer.toString(X);
String YX = Integer.toString(Y);
String QW = XY + YX;
String WE = YX + XY;
return QW.compareTo(WE);
}
}
The program is complied but it fails for the test case array with input 00000.It says function is returning 00000 instead of 0.