Solved
This commit is contained in:
@@ -91,9 +91,49 @@ typedef vector<int> vi;
|
||||
#define pb push_back
|
||||
|
||||
class Solution {
|
||||
private:
|
||||
int toIdx(char x) {
|
||||
if (x == 'a') return 0;
|
||||
if (x == 'e') return 1;
|
||||
if (x == 'i') return 2;
|
||||
if (x == 'o') return 3;
|
||||
if (x == 'u') return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
int minLast(int last[5]) {
|
||||
int res = last[0];
|
||||
for (int i = 1; i < 5; i++) res = min(last[i], res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public:
|
||||
int countVowelSubstrings(string word) {
|
||||
|
||||
int n = word.size();
|
||||
int res = 0;
|
||||
int start = 0;
|
||||
|
||||
int last[5];
|
||||
memset(last, -1, sizeof(last));
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
int idx = toIdx(word[j]);
|
||||
|
||||
// Have const
|
||||
if (idx > 4) {
|
||||
start = j + 1;
|
||||
memset(last, -1, sizeof(last));
|
||||
continue;
|
||||
}
|
||||
|
||||
last[idx] = j;
|
||||
int minLst = minLast(last);
|
||||
|
||||
if (minLst != -1) {
|
||||
res += minLst - start + 1;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user