- first attempt
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if(strs.size()==0)
return "";
if(strs.size()==1)
return strs[0];
string common="";
int twomin= strs[0].size()<strs[1].size()?strs[0].size():strs[1].size();
for(int i = 0 ; i <twomin ; i++)
if(strs[0][i]==strs[1][i])
common+=strs[0][i];
else
break;
for(int j = 2; j < strs.size() ; j++)
while(strs[j].compare(0,common.size(),common)!=0)
{
common.pop_back();
}
return common;
}
};