-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathLeetCode#110.cc
More file actions
27 lines (23 loc) · 801 Bytes
/
Copy pathLeetCode#110.cc
File metadata and controls
27 lines (23 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
vector<string> anagrams(vector<string> &strs) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<string> ret;
map<string,vector<string> > _hash;
for(int i=0;i<strs.size();i++){
string tmp = strs[i];
sort(tmp.begin(),tmp.end());
_hash[tmp].push_back(strs[i]);
}
for(map<string,vector<string> >::iterator it = _hash.begin();
it != _hash.end(); it++){
vector<string>& vec = it->second;
if(vec.size() > 1){
for(int i=0;i<vec.size();++i)
ret.push_back(vec[i]);
}
}
return ret;
}
};