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 81a5acb commit e09e587Copy full SHA for e09e587
group-anagrams/casentino.ts
@@ -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