Skip to content

Commit b2c601a

Browse files
author
Pranjal
authored
Merge pull request royalpranjal#34 from muditjoshi98/master
Reduced code size for Anagram.cpp
2 parents fc7a2bd + d3facea commit b2c601a

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

Hashing/Anagrams.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
// https://www.interviewbit.com/problems/anagrams/
22

3-
string mySort(string temp){
4-
vector<int> str;
5-
for(int i = 0; i < temp.size(); i++){
6-
str.push_back((int)temp[i]);
7-
}
8-
sort(str.begin(), str.end());
9-
string ans = "";
10-
for(int i = 0; i < str.size(); i++){
11-
ans = ans + (char)str[i];
12-
}
13-
14-
return ans;
15-
}
16-
173
vector<vector<int> > Solution::anagrams(const vector<string> &A) {
18-
// Do not write main() function.
19-
// Do not read input, instead use the arguments to the function.
20-
// Do not print the output, instead return values as specified
21-
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
22-
234
vector<vector<int> > sol;
245
unordered_map<string, vector<int> > myMap;
25-
6+
string temp;
267
for(int i = 0; i < A.size(); i++){
27-
string temp = mySort(A[i]);
8+
temp = A[i];
9+
sort(temp.begin(),temp.end());
2810
myMap[temp].push_back(i+1);
2911
}
3012

0 commit comments

Comments
 (0)