class Solution { public: vector<string> anagrams(vector<string> &strs) { vector<string> res; map<string, vector<string>> strmap; int size = strs.size(); for(auto it=strs.begin(); it!=strs.end(); it++) { string s = *it; sort(s.begin(), s.end()); strmap[s].push_back(*it); } for(auto it=strmap.begin(); it!=strmap.end(); it++) { if(it->second.size() > 1) res.insert(res.end(), it->second.begin(), it->second.end()); } return res; } };