49. Group Anagrams
这道题是242Valid Anagram这道题目的升级版,242是判断两个字符串是不是Anagram,现在是将多个Anagram字符串归类到一起。

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> mp;
        vector<vector<string>> res;
        for(auto str:strs)
        {
            string s = str;
            sort(s.begin(),s.end());
            mp[s].push_back(str);
        }
        
        for(auto p : mp)
        {
            res.push_back(p.second);
        }
        
        return res;
    }
};