Longest Substring Of All Vowels in Order LeetCode solution in JavaScript

1
/**
2
* @param {string} word
3
* @return {number}
4
*/
5
var longestBeautifulSubstring = function (word) {
6
let obj = { a: 1, e: 2, i: 3, o: 4, u: 5 };
7
let seq = 0;
8
let maxstrcount = 0,
9
strcount = "";
10
for (let i = 0; i <= word.length; i++) {
11
if (seq <= obj[word[i]]) {
12
strcount += word[i];
13
seq = obj[word[i]];
14
} else {
15
let set = new Set();
16
for (let i = 0; i < strcount.length; i++) {
17
set.add(strcount[i]);
18
}
19
if (set.size == 5) {
20
maxstrcount = Math.max(strcount.length, maxstrcount);
21
}
22
if (i < word.length - 1) i--;
23
strcount = "";
24
seq = 0;
25
}
26
}
27
return maxstrcount;
28
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0