Skip to content

Commit 5c00e0c

Browse files
authored
Update 1839-longest-substring-of-all-vowels-in-order.js
1 parent 07718d5 commit 5c00e0c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

+30
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,36 @@ function longestBeautifulSubstring(word) {
2424
return res
2525
}
2626

27+
// another
28+
29+
/**
30+
* @param {string} word
31+
* @return {number}
32+
*/
33+
function longestBeautifulSubstring(word) {
34+
let res = 0, cur = 'a', cnt = 0
35+
const set = new Set()
36+
for (let ch of word) {
37+
if (ch >= cur) {
38+
cnt++
39+
cur = ch
40+
set.add(ch)
41+
} else {
42+
set.clear()
43+
cnt = 0
44+
cur = 'a'
45+
if(ch === cur) {
46+
set.add(ch)
47+
cnt++
48+
}
49+
}
50+
if (set.size === 5) {
51+
res = Math.max(res, cnt)
52+
}
53+
}
54+
55+
return res
56+
}
2757

2858
// another
2959

0 commit comments

Comments
 (0)