原题链接:https://leetcode.com/problems/group-anagrams/
先排序
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> mp;
for (auto s : strs) {
string str = s;
sort(str.begin(), str.end());
mp[str].push_back(s);
}
vector<vector<string>> res;
for (auto &x : mp) {
res.push_back(x.second);
}
return res;
}
};