Why is my solution giving TLE? C++ CODE!


#1

bool mycompare (string a,string b)
{
string ab=a.append(b);
string ba=b.append(a);
return ab.compare(ba)>0?1:0;
}
string Solution::largestNumber(const vector &A) {
vector v;
string ans ="";
int count=0;
for (int i=0;i<A.size();i++)
{
if (A[i]==0)
{
count+=1;
}
v.push_back(to_string(A[i]));
}
if (count==A.size())
{
return(“0”);
}
sort(v.begin(),v.end(),mycompare);
for (auto i:v)
{
ans=ans+i;
}
return(ans);
}