字母异位词分组
题目链接:https://leetcode-cn.com/problems/group-anagrams/
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, int> hashmap;
vector<vector<string>> res;
for(auto str : strs)
{
auto tmp = str;
sort(tmp.begin(), tmp.end());
if(hashmap.count(tmp))
{
res[hashmap[tmp]].push_back(str);
}
else
{
hashmap[tmp] = res.size();
res.push_back({str});
}
}
return res;
}
};