Skip to content

Commit

Permalink
Update 49-Group-Anagrams.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rutanshuj authored Jul 23, 2022
1 parent 742d19c commit b1f182a
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions javascript/49-Group-Anagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,6 @@
// This solution is faster than sorting each word.
//////////////////////////////////////////////////////////////////////////////

/** @const {!Object<string, number>} */
const CODES = {
a: 0,
b: 1,
c: 2,
d: 3,
e: 4,
f: 5,
g: 6,
h: 7,
i: 8,
j: 9,
k: 10,
l: 11,
m: 12,
n: 13,
o: 14,
p: 15,
q: 16,
r: 17,
s: 18,
t: 19,
u: 20,
v: 21,
w: 22,
x: 23,
y: 24,
z: 25,
};

/**
* @param {string[]} words
* @return {string[][]}
Expand Down Expand Up @@ -63,7 +33,7 @@ function groupAnagrams(words) {
function hashWord(word) {
const hash = new Array(26).fill(0);
for (const ch of word) {
++hash[CODES[ch]];
++hash[ch.charCodeAt(0) - 'a'.charCodeAt(0)];
}
return hash.toString();
}
Expand Down

0 comments on commit b1f182a

Please sign in to comment.