File tree Expand file tree Collapse file tree 1 file changed +3
-21
lines changed Expand file tree Collapse file tree 1 file changed +3
-21
lines changed Original file line number Diff line number Diff line change 1
1
// https://www.interviewbit.com/problems/anagrams/
2
2
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
-
17
3
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
-
23
4
vector<vector<int > > sol;
24
5
unordered_map<string, vector<int > > myMap;
25
-
6
+ string temp;
26
7
for (int i = 0 ; i < A.size (); i++){
27
- string temp = mySort (A[i]);
8
+ temp = A[i];
9
+ sort (temp.begin (),temp.end ());
28
10
myMap[temp].push_back (i+1 );
29
11
}
30
12
You can’t perform that action at this time.
0 commit comments