49. 字母异位词分组

This commit is contained in:
2025-08-09 22:31:05 +08:00
parent c783a5ff9c
commit 2d390fedb8

16
test002.cpp Normal file
View File

@@ -0,0 +1,16 @@
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> data;
for(const auto &s : strs){
auto key = s;
sort(key.begin(), key.end());
data[key].push_back(s);
}
vector<vector<string>> ret;
for(const auto &line : data){
ret.push_back(line.second);
}
return ret;
}
};