class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
string ans = "";
if(strs.size()==0)
return ans;
int i=0;
while(strs[0][i]!='\0'){
char p = strs[0][i];
for(int j = 1;j<strs.size();j++){
if(strs[j][i]!=p)
return ans;
}
ans += p;
i++;
}
return ans;
}
};
public:
string longestCommonPrefix(vector<string> &strs) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
string ans = "";
if(strs.size()==0)
return ans;
int i=0;
while(strs[0][i]!='\0'){
char p = strs[0][i];
for(int j = 1;j<strs.size();j++){
if(strs[j][i]!=p)
return ans;
}
ans += p;
i++;
}
return ans;
}
};