Largest Number
bool comp(string n1, string n2) {
return n1 + n2 > n2 + n1;
}
string Solution::largestNumber(const vector<int> &A) {
string result;
vector<string> str;
bool allZero = true;
for(int x: A) {
if(allZero && x) allZero = false;
str.push_back(to_string(x));
}
if(allZero) return "0";
sort(str.begin(), str.end(), comp);
for(string x: str)
result += x;
return result;
}
Last updated