Skip to content

Commit 561469b

Browse files
committed
Time: 37 ms (28.61%) | Memory: 21.1 MB (62.43%) - LeetSync
1 parent 8580f11 commit 561469b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

49-group-anagrams/group-anagrams.cpp

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

0 commit comments

Comments
 (0)