# My java based solution using a recursive comparator

• ``````import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

public class Solution {

public String largestNumber(int[] num) {

for (int i = 0; i < num.length; i++) {
}

Collections.sort(numList, new NumberComparator());

StringBuffer sb = new StringBuffer();
for (Number number : numList) {
sb.append(new Integer(number.num).toString());
}

return removeTrailingZeros(sb.toString());
}

private String removeTrailingZeros(String str) {
int zeroCount = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '0')
zeroCount++;
}
return (zeroCount == str.length() ? "0" : str);
}

}

class Number {
int num;

public Number(int num) {
this.num = num;

int val = num;

while (val != 0) {
val = val / 10;
}

if (num == 0)
}

public Number() {
}

};

class NumberComparator implements Comparator<Number> {

@Override
public int compare(Number o1, Number o2) {

Iterator<Integer> iter1 = o1.digits.iterator();
Iterator<Integer> iter2 = o2.digits.iterator();

while (iter1.hasNext() && iter2.hasNext()) {
int dig1 = iter1.next();
int dig2 = iter2.next();

if (dig1 > dig2)
return -1;
else if (dig2 > dig1)
return 1;
}

if (!iter1.hasNext() && !iter2.hasNext())
return 0;

else if (!iter1.hasNext()) {
Number newNum = new Number();
while (iter2.hasNext()) {
}
return compare(o1, newNum);
} else {
Number newNum = new Number();
while (iter1.hasNext()) {