题目:
代码(首刷看解析 2024年3月2日):
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> groups;
for (const string& str : strs) {
string key = str;
sort(key.begin(), key.end());
groups[key].push_back(str);
}
vector<vector<string>> result;
for (const unordered_map<string, vector<string>>::value_type& it : groups)
result.push_back(it.second);
return result;
}
};