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 514f317 commit d63b92eCopy full SHA for d63b92e
group-anagrams/gitsunmin.ts
@@ -0,0 +1,17 @@
1
+/**
2
+ * https://leetcode.com/problems/group-anagrams
3
+ * time complexity : O(n * k log k)
4
+ * space complexity : O(n * k)
5
+ */
6
+function groupAnagrams(strs: string[]): string[][] {
7
+ const map = new Map();
8
+
9
+ for (const str of strs) {
10
+ const sortedStr = str.split("").sort().join("");
11
12
+ if (map.has(sortedStr)) map.get(sortedStr).push(str);
13
+ else map.set(sortedStr, [str]);
14
+ }
15
16
+ return Array.from(map.values());
17
+};
0 commit comments