HugeNumber { String hugeNumber(String[] nums) { if (nums == null || nums.length == 0) return ""; Comparator<String> cmp = new Comparator<String>() { @Override public int compare(String o1, String o2) { int l1 = o1.length(), l2 = o2.length(); if (l1 > l2) { if (o1.substring(0, l2).equals(o2) && !o1.startsWith("0")) { return compare(o1.substring(l2), o2); } } if(l1 < l2) { if (o2.substring(0, l1).equals(o1) && !o2.startsWith("0")) { return compare(o1, o2.substring(l1)); } } return o1.compareTo(o2); } }; Arrays.sort(nums, cmp); StringBuilder s = new StringBuilder(); for (String n : nums) { s.insert(0, n); } int leadingZero = 0; while (leadingZero < s.length() && s.substring(leadingZero, leadingZero + 1).equals("0")) { leadingZero++; } return s.substring(leadingZero, s.length()); }    }
@Test(dataProvider = "numsAndHugest") public void testHugeNumber(String[] nums, String expected) { assertEquals(new HugeNumber().hugeNumber(nums), expected); }