c++
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if(strs.size()==0)
return "";
int i=0;
string ans="";
while(true)
{
if(i==strs[0].length())
return ans;
char s=strs[0][i];
for(int j=1;j<strs.size();j++)
{
if(i==strs[j].length())
return ans;
if(strs[j][i]!=s)
return ans;
}
ans+=s;
i++;
}
return ans;
}
};