class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
//总结:分组做法:建立这样的映射 map<string, vector<string>> mp!!!
map<string, vector<string>> mp; //映射:键为排序后的字符串,值为vector
vector<vector<string>> result;
string temp;
for (int i = 0; i < strs.size(); i++){
temp = strs[i];
sort(strs[i].begin(), strs[i].end()); //先排序
mp[strs[i]].push_back(temp);
}
for (map<string, vector<string>>::iterator it = mp.begin(); it != mp.end(); it++){
result.push_back(it -> second);
}
return result;
}
};