Java AC 273ms
public class Solution { public String largestNumber(int[] num) { int len = num.length; String array[] = new String[len]; for (int i = 0; i < len; i++) { array[i] = String.valueOf(num[i]); } Arrays.sort(array, new MySort()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i++) { sb.append(array[i]); } String result = sb.toString(); if ("".equals(result.replace("0",""))) { return "0"; } return sb.toString(); } public class MySort implements Comparator<String> { @Override public int compare(String o1, String o2) { return (o2 + o1).compareTo(o1 + o2); } } }Python AC 132ms
class Solution: # @param num, a list of integers # @return a string def largestNumber(self, num): num = sorted(num, cmp=lambda x, y: cmp(str(y) + str(x), str(x) + str(y))) print num sb = '' for x in num: sb += str(x) if sb.replace('0', '') == '': return '0' return sb