Skip to content

Commit 9d551b4

Browse files
authored
Create 12_groupAnagrams.cpp
1 parent ded6612 commit 9d551b4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
vector<vector<string>> groupAnagrams(vector<string>& strs) {
4+
unordered_map<string, vector<string>> mp;
5+
for(auto i: strs){
6+
string temp = i;
7+
sort(temp.begin(), temp.end());
8+
mp[temp].push_back(i);
9+
}
10+
11+
vector<vector<string>> res;
12+
for(auto i: mp){
13+
res.push_back(i.second);
14+
}
15+
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)