Skip to content

Commit c53589e

Browse files
committed
Time: 49 ms (25.79%), Space: 63.5 MB (46.1%) - LeetHub
1 parent a183499 commit c53589e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

0049-group-anagrams/0049-group-anagrams.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ function groupAnagrams(strs) {
88
for (let i = 0; i < strs.length; i++) {
99
let counter = new Array(26).fill(0);
1010
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);
11+
let key = String(counter);
12+
if (!map.has(key)) map.set(key, []);
13+
map.get(key).push(strs[i]);
1514
}
16-
return [...map.values()];
15+
return Array.from(map.values());
1716
}

0 commit comments

Comments
 (0)