Longest Substring Of All Vowels in Order LeetCode solution in C++

1
class Solution {
2
public:
3
int longestBeautifulSubstring(string word) {
4
const auto n = word.size();
5

6
int cnt = 1;
7
int len = 1;
8
int max_len = 0;
9
for (int i = 1; i != n; ++i) {
10
if (word[i - 1] == word[i]) {
11
++len;
12
} else if (word[i - 1] < word[i]) {
13
++len;
14
++cnt;
15
} else {
16
cnt = 1;
17
len = 1;
18
}
19

20
if (cnt == 5) {
21
max_len = max(max_len, len);
22
}
23
}
24
return max_len;
25
}
26
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0