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 28c30e7 commit e92b357Copy full SHA for e92b357
group-anagrams/sunjae95.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @description
3
+ * brainstorming:
4
+ * brute force + hashtable
5
+ *
6
+ * time complexity: O(n* k log k)
7
+ * space complexity: O(n* k)
8
+ */
9
+var groupAnagrams = function (strs) {
10
+ const map = new Map();
11
+ const answer = [];
12
+
13
+ strs.forEach((str) => {
14
+ const convertedStr = str.split("").sort().join();
15
+ if (map.has(convertedStr))
16
+ map.set(convertedStr, map.get(convertedStr).concat(str));
17
+ else map.set(convertedStr, [str]);
18
+ });
19
20
+ map.forEach((value) => answer.push(value));
21
22
+ return answer;
23
+};
0 commit comments