Write a function to find the longest common prefix string amongst an array of strings.
题解:
简单的暴力遍历解决
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
int n = strs.size();
if (n < || strs[].empty())
return "";
string res; for (int j = ; j < strs[].size(); ++j) {
char c = strs[][j];
for (int i = ; i < strs.size(); ++i) {
if (j >= strs[i].size() || strs[i][j] != c)
return res;
} res += c;
} return res;
}
};