class Solution { public: vector> groupAnagrams(vector & strs) { unordered_map >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 >(str1, vector {str})); else it->second.push_back(str); } vector >ret; for(auto x:a) { ret.push_back(x.second); } return ret; } };
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)