Skip to content

Commit 24a308f

Browse files
committed
group anagrams solution
1 parent 3ec3042 commit 24a308f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

group-anagrams/limlimjo.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string[]} strs
3+
* @return {string[][]}
4+
*/
5+
var groupAnagrams = function (strs) {
6+
// map에 담기
7+
const map = new Map();
8+
9+
// for문 돌기
10+
for (const str of strs) {
11+
// 정렬된 단어
12+
const sortWord = str.split("").sort().join("");
13+
// map에 가지고 있지 않을 때
14+
if (!map.has(sortWord)) {
15+
map.set(sortWord, []);
16+
}
17+
map.get(sortWord).push(str);
18+
}
19+
20+
return Array.from(map.values());
21+
};

0 commit comments

Comments
 (0)