Skip to content

Commit e09e587

Browse files
committed
Group Anagram
1 parent 81a5acb commit e09e587

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

group-anagrams/casentino.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function groupAnagrams(strs: string[]): string[][] {
2+
const hashMap = new Map();
3+
for (let i = 0; i < strs.length; i++) {
4+
const key = Array.from(strs[i]).sort().join("");
5+
6+
if (!hashMap.has(key)) {
7+
hashMap.set(key, [strs[i]]);
8+
} else {
9+
hashMap.get(key).push(strs[i]);
10+
}
11+
}
12+
return Array.from(hashMap.values());
13+
}

0 commit comments

Comments
 (0)