Skip to content

Commit e0f8858

Browse files
committed
solved: 49
1 parent 13ba086 commit e0f8858

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

code/49.group-anagrams.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @leet start
2+
function groupAnagrams(strs: string[]): string[][] {
3+
const m = new Map<string, string[]>();
4+
for (const str of strs) {
5+
const key = str.split("").sort().join("");
6+
if (m.has(key)) {
7+
m.get(key).push(str);
8+
} else {
9+
m.set(key, [str]);
10+
}
11+
}
12+
13+
return Array.from(m.values());
14+
}
15+
// @leet end
16+

0 commit comments

Comments
 (0)