Skip to content

Commit 9bd9372

Browse files
committed
feat(soobing): group-anagrams
1 parent fdf3120 commit 9bd9372

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

group-anagrams/soobing.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function groupAnagrams(strs: string[]): string[][] {
2+
const map = new Map<string, string[]>();
3+
4+
for (let i = 0; i < strs.length; i++) {
5+
const key = strs[i].split("").sort().join("");
6+
const group = map.get(key);
7+
if (group) {
8+
group.push(strs[i]);
9+
} else {
10+
map.set(key, [strs[i]]);
11+
}
12+
}
13+
return [...map.values()];
14+
}

0 commit comments

Comments
 (0)