Skip to content

Commit 0f0fac9

Browse files
committed
Merge branch 'patch-1' of https://github.com/jakwings/leetcode into jakwings-patch
2 parents 6f0059a + 04a4d34 commit 0f0fac9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/anagrams/anagrams.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class Solution {
1414
public:
1515
vector<string> anagrams(vector<string> &strs) {
1616
vector<string> result;
17-
map<string, string> m;
17+
map<string, int> m;
1818
for(int i=0; i<strs.size(); i++){
1919
string word = strs[i];
20-
sort(word.begin(), word.end());
20+
sort(word.begin(), word.end()); // Why not use a better hashing technique?
2121
if (m.find(word)==m.end()){
22-
m[word] = strs[i];
22+
m[word] = i;
2323
}else{
24-
if (m[word]!="#"){
25-
result.push_back(m[word]);
26-
m[word]="#";
24+
if (m[word]>=0){
25+
result.push_back(strs[m[word]]);
26+
m[word]=-1;
2727
}
2828
result.push_back(strs[i]);
2929
}

0 commit comments

Comments
 (0)