Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
class Solution {
public:
std::vector
anagrams(std::vector
&strs) { std::vector
res; std::map
ans; for (int i = 0; i < strs.size(); i++) { std::string s = strs[i]; std::sort(s.begin(),s.end()); if(ans.find(s) != ans.end()) { if(ans[s] >= 0) { res.push_back(strs[ans[s]]); ans[s] = -1; } res.push_back(strs[i]); } else { ans.insert(std::make_pair(s,i)); } } return res; } };