全排列复杂度太高
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>>a;
for(auto str : strs)
{
auto str1=str;
sort(str1.begin(), str1.end());
auto it = a.find(str1);
if(it==a.end())
a.insert(pair<string, vector<string>>(str1, vector<string>{str}));
else
it->second.push_back(str);
}
vector<vector<string>>ret;
for(auto x:a)
{
ret.push_back(x.second);
}
return ret;
}
};