[leetcode]49. Group Anagrams
Analysis
直男真可怕—— [每天刷题并不难0.0]
Given an array of strings, group anagrams together.
Explanation:
用hashtable实现~
Implement
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
vector<vector<string>> res;
unordered_map<string, vector<string>> mp;
for(string str:strs){
string s = str;
sort(s.begin(), s.end());
mp[s].push_back(str);
}
for(auto m:mp){
res.push_back(m.second);
}
return res;
}
};