Skip to content

Commit c296d37

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

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

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

0 commit comments

Comments
 (0)