Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
anagrams:两个字符串,字母相同,出现次数相同的两个字符串互为anagrams
class Solution {
public:
vector<string> anagrams(vector<string> &strs) {
map<string, int> count;
for(int i =0; i < strs.size(); ++i)
{
string tmp = strs[i];
sort(tmp.begin(), tmp.end());
if(count.find(tmp) == count.end())count[tmp] = 1;
else count[tmp]++;
}
vector<string> rst;
for(int i = 0; i < strs.size(); ++i)
{
string tmp = strs[i];
sort(tmp.begin(), tmp.end());
if(count[tmp] > 1)rst.push_back(strs[i]);
}
return rst;
}
};