class Solution {
public:
vector<string> anagrams(vector<string> &strs) {
vector<string> res;
map<string, vector<string>> strmap;
int size = strs.size();
for(auto it=strs.begin(); it!=strs.end(); it++)
{
string s = *it;
sort(s.begin(), s.end());
strmap[s].push_back(*it);
}
for(auto it=strmap.begin(); it!=strmap.end(); it++)
{
if(it->second.size() > 1)
res.insert(res.end(), it->second.begin(), it->second.end());
}
return res;
}
};
LeetCode--Anagrams
最新推荐文章于 2021-09-05 22:05:39 发布