简单题 懒得多说了,反正也没人会看。
bool func1(vector<string>& strs, int sht) {
char s = strs[0][sht];
for (int i = 1; i < strs.size(); ++i) {
if (s != strs[i][sht])
return false;
}
return true;
}
string longestCommonPrefix(vector<string>& strs) {
int back = 0, sht = INT_MAX, sz = strs.size();
if (!sz)
return string();
else if (sz == 1)
return strs[0];
for (int i = 0; i < sz; ++i)
if (sht > strs[i].size())
sht = strs[i].size();
for (int i = 0; i < sht; ++i)
if (!func1(strs, i))
return strs[0].substr(0, i);
return strs[0].substr(0, sht);
}