Skip to content

Commit e4aaeab

Browse files
committed
refactor: 49. Group Anagrams
1 parent 8f6c82f commit e4aaeab

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

group-anagrams/gwbaik9717.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ var groupAnagrams = function (strs) {
1111
const anagramDict = new Map();
1212

1313
const getKey = (str) => {
14+
const minCharCode = "a".charCodeAt();
15+
const maxCharCode = "z".charCodeAt();
16+
1417
const counter = Array.from(
15-
{ length: "z".charCodeAt() - "a".charCodeAt() + 1 },
18+
{ length: maxCharCode - minCharCode + 1 },
1619
() => 0
1720
);
1821

1922
for (const chr of str) {
20-
const index = chr.charCodeAt() - "a".charCodeAt();
23+
const index = chr.charCodeAt() - minCharCode;
2124
counter[index]++;
2225
}
2326

0 commit comments

Comments
 (0)