Leetcode 49 Solution

This article provides solution to leetcode question 49 (group-anagrams)

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; } };