Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ba6a1c

Browse files
authored
Merge pull requestneetcode-gh#603 from neetcode-gh/revert-602-patch-2
Revert "Update 49-Group-Anagrams.js"
2 parents7c38239 +7e1023a commit5ba6a1c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

‎javascript/49-Group-Anagrams.js‎

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

8+
/**@const {!Object<string, number>} */
9+
constCODES={
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+
838
/**
939
*@param {string[]} words
1040
*@return {string[][]}
@@ -33,7 +63,7 @@ function groupAnagrams(words) {
3363
functionhashWord(word){
3464
consthash=newArray(26).fill(0);
3565
for(constchofword){
36-
++hash[ch.charCodeAt(0)-'a'.charCodeAt(0)];
66+
++hash[CODES[ch]];
3767
}
3868
returnhash.toString();
3969
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp