# Middle-题目120：179. Largest Number

Middle-题目120：179. Largest Number

Given a list of non negative integers, arrange them such that they form the largest number.

For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.

Note: The result may be very large, so you need to return a string instead of an integer.

public class Solution {
private class MyComparator implements Comparator<Integer> {
public int compare(Integer o1, Integer o2) {
// TODO Auto-generated method stub
String s1=o1.toString()+o2.toString();
String s2=o2.toString()+o1.toString();
return s2.compareTo(s1);
}
}
public String largestNumber(int[] nums) {
List<Integer> list = new ArrayList<Integer>();
for(int num:nums)
Collections.sort(list, new MyComparator());
String result = "";
for(Integer i:list)
result+=String.valueOf(i);
if(result.startsWith("00"))
result = "0";
return result;
}
}

123ms,beats 64.21%,众数123ms,6.42%
Cmershen的碎碎念：

• 本文已收录于以下专栏：

举报原因： 您举报文章：Middle-题目120：179. Largest Number 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)