std::string Algorithm::longestCommonPrefix(vector<string>& strs)
{
std::string strCommon;
int iSz = strs.size();
if (iSz >= 1)
{
strCommon = strs.at(0);
}
for (int i = 0; i < iSz; i++)
{
std::string strCur = strs.at(i);
int nCom = strCommon.length();
int nCur = strCur.length();
if (nCur < nCom)
{
nCom = nCur;
}
std::string strNew;
for (int j = 0; j < nCom; j++)
{
if (strCommon[j] == strCur[j])
{
strNew.push_back(strCommon[j]);
}
else
{
break;
}
}
strCommon = strNew;
if (strCommon.length() == 0)
{
break;
}
}
return strCommon;
}