Created
January 8, 2015 12:24
-
-
Save marius92mc/8de46e3b460742dfd1e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<string> anagrams(vector<string> &strs) | |
{ | |
int strs_size = strs.size(); | |
vector<string> result; | |
map<string, vector<string> > m; | |
for (int i = 0; i < strs_size; i++) | |
{ | |
string temp = strs[i]; | |
sort(temp.begin(), temp.end()); | |
m[temp].push_back(strs[i]); | |
} | |
for (auto it = m.begin(); it != m.end(); it++) | |
{ | |
vector<string> words = it->second; | |
int count_words = words.size(); | |
for (int j = 0; j < count_words; j++) | |
result.push_back(words[j]); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment