![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6654e1eac42675c910bf558c35355c72.png)
纵向扫描
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string ans;
if(strs.empty())return ans;
for(int i=0;;i++){
if(i>=strs[0].size())return ans;
char c=strs[0][i];
for(auto str:strs){
if(str.size()<=i || str[i]!=c)return ans;
}
ans+=c;
}
return ans;
}
};