Skip to content

Commit b1f182a

Browse files
authored
Update 49-Group-Anagrams.js
1 parent 742d19c commit b1f182a

File tree

1 file changed

+1
-31
lines changed

1 file changed

+1
-31
lines changed

javascript/49-Group-Anagrams.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,6 @@
55
// This solution is faster than sorting each word.
66
//////////////////////////////////////////////////////////////////////////////
77

8-
/** @const {!Object<string, number>} */
9-
const CODES = {
10-
a: 0,
11-
b: 1,
12-
c: 2,
13-
d: 3,
14-
e: 4,
15-
f: 5,
16-
g: 6,
17-
h: 7,
18-
i: 8,
19-
j: 9,
20-
k: 10,
21-
l: 11,
22-
m: 12,
23-
n: 13,
24-
o: 14,
25-
p: 15,
26-
q: 16,
27-
r: 17,
28-
s: 18,
29-
t: 19,
30-
u: 20,
31-
v: 21,
32-
w: 22,
33-
x: 23,
34-
y: 24,
35-
z: 25,
36-
};
37-
388
/**
399
* @param {string[]} words
4010
* @return {string[][]}
@@ -63,7 +33,7 @@ function groupAnagrams(words) {
6333
function hashWord(word) {
6434
const hash = new Array(26).fill(0);
6535
for (const ch of word) {
66-
++hash[CODES[ch]];
36+
++hash[ch.charCodeAt(0) - 'a'.charCodeAt(0)];
6737
}
6838
return hash.toString();
6939
}

0 commit comments

Comments
 (0)