题目:https://leetcode.com/problems/longest-common-prefix/#/description
代码:
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
if(strs.size() == 0)return "";
int len = strs[0].size();
for(int i = 1; i < strs.size() ; i++)
{
int j;
for(j = 0; j < min(len, (int)strs[i].size()); j++)
if(strs[0][j] != strs[i][j])break;
if(len > j)len = j;
}
return strs[0].substr(0, len);
}
};