题目
代码
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> mp;
for (string& str: strs) {
string key = str;
sort(key.begin(), key.end());
mp[key].push_back(str);//mp的value是字符数组,所将排序好后的key相同的str都加入这个value中去。//还有这算是map的又一种插入方式
}
vector<vector<string>> ans;
for (auto it = mp.begin(); it != mp.end(); ++it) {
ans.push_back(it->second);//指向second你是得到了这个map的value
}
return ans;
}
};