class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
vector<vector<string>> res;
if (strs.empty()) {
return res;
}
map<string, vector<string>> m1;
for (int i = 0; i < strs.size(); i++) {
string key = strs[i];
sort(key.begin(), key.end());
m1[key].push_back(strs[i]);
}
for (map<string, vector<string>>::iterator it= m1.begin(); it != m1.end(); it++) {
res.push_back(it->second);
}
return res;
}
};