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 448f741 commit 4844d5dCopy full SHA for 4844d5d
group-anagrams/krokerdile.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @param {string[]} strs
3
+ * @return {string[][]}
4
+ */
5
+var groupAnagrams = function(strs) {
6
+ const dict = new Map();
7
+
8
+ strs.forEach(str => {
9
+ const sorted = str.split('').sort().join('');
10
+ if (!dict.has(sorted)) {
11
+ dict.set(sorted, [str]);
12
+ } else {
13
+ dict.get(sorted).push(str);
14
+ }
15
+ });
16
17
+ // value 길이 기준 내림차순 정렬
18
+ const result = [...dict.entries()]
19
+ .sort((a, b) => b[1].length - a[1].length)
20
+ .map(([_, group]) => group); // value (즉, 아나그램 그룹)만 꺼냄
21
22
+ return result;
23
+};
0 commit comments