How is this solution?


#1
string Solution::longestCommonPrefix(vector<string> &A) {
if(A.size()==1) return A[0];
string sout = "";
sort(A.begin(),A.end());

auto it = A.rbegin(); 

int l= 1;

string s1 = A[0];
string s2 = *it;

//cout<<s1<<" "<<s2<<endl;
int i=0;
while(1)
{   
    if(s1[i] == s2[i]) {sout+=s1[i];i++;}
    else break;
}

return sout;

}


#2

Why are u sorting it?