Group Anagrams LeetCode solution in C++

1
class Solution {
2
public:
3
vector<vector<string>> groupAnagrams(vector<string> &strs) {
4
map<string, vector<int>> mp;
5
for (int i = 0; i < strs.size(); i++) {
6
string t = strs[i];
7
sort(t.begin(), t.end());
8
mp[t].push_back(i);
9
}
10
vector<vector<string>> ans;
11
for (auto it : mp) {
12
vector<string> flag;
13
for (auto each : it.second) {
14
flag.push_back(strs[each]);
15
}
16
ans.push_back(flag);
17
}
18

19
return ans;
20
}
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0