Correct solution for this problem


#1

static bool comp(string X,string Y)
{
return (X+Y)>(Y+X);
}

string Solution::largestNumber(const vector &A) {
vector str;
int count=0;
for(int i=0;i<A.size();i++)
str.push_back(to_string(A[i]));
sort(str.begin(),str.end(),comp);
string S;
for(int i=0;i<str.size();i++)
S+=str[i];
for(int i=0;i<S.length();i++)
{
if(S[i]==‘0’)
count++;
}
if(count==S.length())
return “0”;
return S;
}


#2

You can simplify your code more just by removing the loop that were count only the number of zeros. No need to count the zeros but you can only return “0” if you encounter the “0” on 0-index. Then you whole code will simplify and looks good.:blush::blush: