We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a183499 commit c53589eCopy full SHA for c53589e
0049-group-anagrams/0049-group-anagrams.js
@@ -8,10 +8,9 @@ function groupAnagrams(strs) {
8
for (let i = 0; i < strs.length; i++) {
9
let counter = new Array(26).fill(0);
10
strs[i].split('').forEach(e => counter[e.charCodeAt(0)-'a'.charCodeAt(0)]++)
11
- let key = counter.join();
12
- let val = map.get(key) || [];
13
- val.push(strs[i]);
14
- map.set(key, val);
+ let key = String(counter);
+ if (!map.has(key)) map.set(key, []);
+ map.get(key).push(strs[i]);
15
}
16
- return [...map.values()];
+ return Array.from(map.values());
17
0 commit comments