Skip to content

Commit 4fdf36f

Browse files
committed
49. Group Anagrams
1 parent 72bf421 commit 4fdf36f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

group-anagrams.cpp

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

0 commit comments

Comments
 (0)