Leetcode 49 Solution
This article provides solution to leetcode question 49 (group-anagrams)
Access this page by simply typing in "lcs 49" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/group-anagrams
Solution
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> m;
for (auto str : strs)
{
auto key = str;
sort(key.begin(), key.end());
m[key].push_back(str);
}
vector<vector<string>> res;
for (auto pair : m)
res.push_back(pair.second);
return res;
}
};