Skip to content

Commit 039362f

Browse files
authored
Update 1371-find-the-longest-substring-containing-vowels-in-even-counts.js
1 parent c296d37 commit 039362f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

+29
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,35 @@ const findTheLongestSubstring = function(s) {
2525

2626
// another
2727

28+
/**
29+
* @param {string} s
30+
* @return {number}
31+
*/
32+
const findTheLongestSubstring = function(s) {
33+
const n = s.length
34+
let res = 0, mask = 0
35+
const map = new Map([[0, -1]])
36+
37+
for(let i = 0; i < n; i++) {
38+
const ch = s[i]
39+
const idx = 'aeiou'.indexOf(ch)
40+
if(idx !== -1) {
41+
mask ^= (1 << idx)
42+
if(map.has(mask)) {
43+
res = Math.max(res, i - map.get(mask))
44+
} else {
45+
map.set(mask, i)
46+
}
47+
} else {
48+
res = Math.max(res, i - map.get(mask))
49+
}
50+
}
51+
52+
return res
53+
};
54+
55+
// another
56+
2857
/**
2958
* @param {string} s
3059
* @return {number}

0 commit comments

Comments
 (0)