leetcode-----49. 字母异位词分组
代码
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> map;
for (auto &str: strs) {
string key = str;
sort(key.begin(), key.end());
map[key].push_back(move(str));
}
vector<vector<string>> ans;
for (auto i = map.begin(); i != map.end(); ++i) {
ans.push_back(move(i->second));
}
return ans;
}
};