Skip to content

Commit 941f878

Browse files
authored
Update 1371-find-the-longest-substring-containing-vowels-in-even-counts.js
1 parent caadda0 commit 941f878

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

1371-find-the-longest-substring-containing-vowels-in-even-counts.js

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const findTheLongestSubstring = function(s) {
6+
const n = s.length
7+
const ch2num = ch => {
8+
const idx = 'aeiou'.indexOf(ch)
9+
return idx === -1 ? 0 : (1 << idx)
10+
}
11+
let res = 0
12+
let mask = 0
13+
const hash = new Map([[0, -1]])
14+
for (let i = 0; i < n; i++) {
15+
mask ^= ch2num(s[i])
16+
const first = hash.has(mask) ? hash.get(mask) : i
17+
if (!hash.has(mask)) hash.set(mask, i)
18+
res = Math.max(res, i - first)
19+
}
20+
21+
return res
22+
};
23+
24+
// another
25+
126
/**
227
* @param {string} s
328
* @return {number}

0 commit comments

Comments
 (0)