class Solution {
public:
string longestCommonPrefix(vector<string>& strs)
{
int n = strs.size();
if(n == 0)
return "";
int len = strs[0].size();
for (int i = 1; i < n; ++i)
{
int j = 0;
for(j = 0 ; j < min(len , (int)strs[i].size()); ++j)
if(strs[i][j] != strs[0][j])
break;
if (len > j)
len = j;
}
return strs[0].substr(0, len);
}
};
Longest Common Prefix
最新推荐文章于 2016-08-02 11:21:30 发布