C++ unordered_map and counting sort
Use an unordered_map to group the strings by their sorted counterparts. Use the sorted string as the key and all anagram strings as the value.\n\ncpp\nclass Sol
Use an `unordered_map` to group the strings by their sorted counterparts. Use the sorted string as the key and all anagram strings as the value.\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<string>> groupAnagrams(vector<string>& strs) {\n        unordered_map<string, vector<string>> mp;\n        for (string s : strs) {\n            string t = s; \n            sort(t.begin(), t.end());\n            mp[t].push_back(s);\n        }\n        vector<vector<string>> anagrams;\n        for (auto p : mp) { \n            anagrams.push_back(p.second);\n        }\n        return anagrams;\n    }\n};\n```\n\nMoreover, since the string only contains lower-case alphabets, we can sort them using counting sort to improve the time complexity.\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<string>> groupAnagrams(vector<string>& strs) {\n        unordered_map<string, vector<string>> mp;\n        for (string s : strs) {\n            mp[strSort(s)].push_back(s);\n        }\n        vector<vector<string>> anagrams;\n        for (auto p : mp) { \n            anagrams.push_back(p.second);\n        }\n        return anagrams;\n    }\nprivate:\n    string strSort(string s) {\n        int counter[26] = {0};\n        for (char c : s) {\n            counter[c - \'a\']++;\n        }\n        string t;\n        for (int c = 0; c < 26; c++) {\n            t += string(counter[c], c + \'a\');\n        }\n        return t;\n    }\n};\n```
['String', 'C++']