【LeetCode】49. 字母異位詞分組【STL】
阿新 • • 發佈:2020-12-15
技術標籤:# LeetCode
傳送門
思路
unordered的簡單使用
AC程式碼
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string,vector<string>> mp;
for(auto &str: strs){
string key = str;
sort (key.begin(),key.end());
mp[key].push_back(str);
}
vector<vector<string> > ans;
for(auto it = mp.begin(); it != mp.end(); it++){
ans.push_back(it->second);
}
return ans;
}
};