class Solution {
public:
vector<string> anagrams(vector<string> &strs) {
unordered_map<string, vector<string> > group;
for(const auto &str: strs)
{
string key = str;
std::sort(key.begin(), key.end());
group[key].push_back(str);
}
vector<string> result;
for(auto it = group.cbegin(); it != group.cend(); it++)
{
if(it->second.size() > 1)
result.insert(result.end(), it->second.begin(), it->second.end());
}
return result;
}
};
使用map对排序后的string进行分类处理。