# Leetcode160: 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.

class Solution {
public:
static bool compare(string& s1, string& s2)
{
return (s1+s2)>(s2+s1);
}
string largestNumber(vector<int>& nums) {
vector<string> num(nums.size());
for(int i = 0; i < nums.size(); i++)
{
num[i] = to_string(nums[i]);
}
sort(num.begin(), num.end(), compare);
string res;
bool flag = false;
for(int i = 0; i < num.size(); i++)
{
if(num[i] != "0"){
res += num[i];
flag = true;
}
else if(flag)
{
res += num[i];
}
}
if(!flag) res.push_back('0');
return res;
}
};

#### 【LeetCode】Largest Number 解题报告

2015-01-13 15:04:39

#### 179 Largest Number

2016-01-31 22:03:04

#### LeetCode(179) Largest Number

2015-01-21 15:58:05

#### [Leetcode] 179. Largest Number @python

2016-02-05 17:00:05

#### leetcode-747. Largest Number Greater Than Twice of Others

2017-12-25 12:26:17

#### 747. Largest Number At Least Twice of Others。

2018-01-07 21:12:12

#### 欧拉计划---0003 Largest prime factor（找出一个合数的最大质数因子）

2015-02-07 17:21:21

#### 179. Largest Number 排成最大的数字（重要！）

2016-06-26 16:44:11

#### LeetCode--Largest Number（最大数字）Python

2017-11-29 15:13:09

#### Largest Number (Java)

2015-01-20 11:02:10