class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
if(strs.empty()) return vector<vector<string>>{};
vector<vector<string>> res;
unordered_map<string, int> m;
int cnt = 0;
for(int i = 0; i < strs.size(); ++i)
{
string e = strs[i];
sort(e.begin(), e.end());
if(m.count(e))
{
res[m[e]].push_back(strs[i]);
}
else
{
m[e] = cnt++;
res.push_back({strs[i]});
}
}
return res;
}
};