classSolution { public: stringlongestCommonPrefix(vector<string>&strs) { sort(strs.begin(),strs.end()); string&s1=strs.front(); string&s2=strs.back(); inti=0; while(i<s1.size()&&i<s2.size()&&s1[i]==s2[i]){ ++i; } returnstring(s1.begin(),s1.begin()+i); } };