建立一个哈希表,记录相同字符序列对应的字符串:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string> > table;
for(int i=0;i<strs.size();i++)
{
string temp=strs[i];
sort(temp.begin(),temp.end());
table[temp].push_back(strs[i]);
}
vector<vector<string>> res;
unordered_map<string,vector<string> >::iterator it=table.begin();
for(;it!=table.end();it++)
res.push_back(it->second);
return res;
}