所有的字符串都只包含小写字母
分析:对每次字母进行排序,然后用hash表记录个数就行
代码:
class Solution {
public:
/**
* @param strs: A list of strings
* @return: A list of strings
*/
vector<string> anagrams(vector<string> &strs) {
// write your code here
map<string,int> m;
for(auto s:strs)
{
sort((),());
m[s]++;
}
vector<string> ret;
for(auto s:strs)
{
auto temp = s;
sort((),());
if(m[temp]>1)
ret.push_back(s);
}
return ret;
}
};