Skip to content

Commit 479a691

Browse files
committed
add solution: group-anagrams
1 parent 1f58190 commit 479a691

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

group-anagrams/yihyun-kim1.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string[]} strs
3+
* @return {string[][]}
4+
*/
5+
const groupAnagrams = (strs) => {
6+
const map = new Map();
7+
8+
for (const str of strs) {
9+
const sorted = str.split("").sort().join("");
10+
11+
if (!map.has(sorted)) {
12+
map.set(sorted, []);
13+
}
14+
map.get(sorted).push(str);
15+
}
16+
17+
return [...map.values()];
18+
};

0 commit comments

Comments
 (0)