文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string result = "";
if(strs.size() == 0) {
return result;
}
string pattern = strs[0];
for(int i = 0; i < pattern.length(); i++) {
char ch = pattern[i];
for(string s : strs) {
if(s[i] != ch) {
return result;
}
}
result += ch;
}
return result;
}
};