Skip to content

Commit 6fd5ea7

Browse files
authored
Update 1839-longest-substring-of-all-vowels-in-order.js
1 parent 0631ed7 commit 6fd5ea7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

1839-longest-substring-of-all-vowels-in-order.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
/**
2+
* @param {string} word
3+
* @return {number}
4+
*/
5+
function longestBeautifulSubstring(word) {
6+
let res = 0, cur = 'a', cnt = 0
7+
const set = new Set()
8+
for(let ch of word) {
9+
if(ch < cur) {
10+
set.clear()
11+
cnt = 0
12+
cur = 'a'
13+
if(ch === cur) {
14+
cnt++
15+
set.add(cur)
16+
}
17+
} else {
18+
cnt++
19+
set.add(ch)
20+
cur = ch
21+
if(set.size === 5) res = Math.max(res, cnt)
22+
}
23+
}
24+
return res
25+
}
26+
27+
28+
// another
29+
130
/**
231
* @param {string} word
332
* @return {number}

0 commit comments

Comments
 (0)