class Solution
{
public:
static bool cmp(string& a,string& b)
{
return a.length()<b.length();
}
vector<string> stringMatching(vector<string>& words)
{
vector<string> ans;
bool flag;
sort(words.begin(),words.end(),cmp);
for(int i=0;i<words.size()-1;i++)
{
for(int j=i+1;i<words.size();j++)
{
flag=false;
if(words[j].find(words[i])!=-1)
{
flag=true;
break;
}
}
if(flag) ans.push_back(words[i]);
}
return ans;
}
};
数组中的字符串匹配
最新推荐文章于 2024-05-16 18:05:18 发布