We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1ad5d21 commit 635eff6Copy full SHA for 635eff6
group-anagrams/hyer0705.ts
@@ -0,0 +1,15 @@
1
+function groupAnagrams(strs: string[]): string[][] {
2
+ const anagramsMap = new Map<string, string[]>();
3
+
4
+ for (const word of strs) {
5
+ const anagramKey = [...word].sort().join();
6
7
+ if (anagramsMap.has(anagramKey)) {
8
+ anagramsMap.get(anagramKey)!.push(word);
9
+ } else {
10
+ anagramsMap.set(anagramKey, [word]);
11
+ }
12
13
14
+ return Array.from(anagramsMap.values());
15
+}
0 commit comments