class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
string s;
vector<vector<string>> ret;
vector<string> num(1,"");
unordered_map<string,int>map;
for(auto it:strs)
{
s=it;
sort(s.begin(),s.end());
if(map.count(s))
{
ret[map[s]].push_back(it);
}else{
map[s]=ret.size();
num[0]=it;
ret.push_back(num);
}
}
return ret;
}
};
leetcode - 49. Group Anagrams
最新推荐文章于 2021-01-04 04:32:24 发布