class Solution {
public:
vector<string> anagrams(vector<string> &strs) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
map<string, vector<string> > dict;
vector<string> res;
for (int i = 0; i < strs.size(); ++i)
{
// store original
string temp(strs[i]);
sort(temp.begin(), temp.end());
dict[temp].push_back(strs[i]);
}
for (map<string, vector<string> >::iterator it = dict.begin(); it != dict.end(); ++it)
{
if ((it->second).size() > 1)
{
for (int i = 0; i < (it->second).size(); ++i)
res.push_back((it->second)[i]);
}
}
return res;
}
};[Leetcode] Anagrams
最新推荐文章于 2020-07-07 20:25:37 发布
390

被折叠的 条评论
为什么被折叠?



