Skip to content

Commit 2f41916

Browse files
authored
Create 1839-longest-substring-of-all-vowels-in-order.js
1 parent 9f49240 commit 2f41916

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {string} word
3+
* @return {number}
4+
*/
5+
function longestBeautifulSubstring(word) {
6+
let result = 0,
7+
current = 0
8+
let currentVowel = "a"
9+
const set = new Set()
10+
for (let i = 0; i < word.length; i++)
11+
if (word.charAt(i) < currentVowel) {
12+
set.clear()
13+
if (word.charAt(i) == "a") {
14+
set.add("a")
15+
current = 1
16+
} else current = 0
17+
currentVowel = "a"
18+
} else {
19+
current++
20+
currentVowel = word.charAt(i)
21+
set.add(currentVowel)
22+
if (set.size == 5) result = Math.max(result, current)
23+
}
24+
return result
25+
}

0 commit comments

Comments
 (0)