-
Notifications
You must be signed in to change notification settings - Fork 3
/
2559.cpp
31 lines (31 loc) · 933 Bytes
/
2559.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public:
bool isVowel(char c) {
if (c == 'a') return true;
if (c == 'e') return true;
if (c == 'i') return true;
if (c == 'o') return true;
if (c == 'u') return true;
return false;
}
bool isValid(string& word) {
int m = word.size();
if (isVowel(word[0]) && isVowel(word[m - 1])) return true;
return false;
}
vector<int> vowelStrings(vector<string>& words, vector<vector<int>>& queries) {
int n = words.size();
int m = queries.size();
vector<int> prefixSum(n + 1, 0);
int count = 0;
for (int i = 0; i < n; ++i) {
count += isValid(words[i]);
prefixSum[i + 1] = count;
}
vector<int> res(m, 0);
for (int i = 0; i < m; ++i) {
res[i] = prefixSum[queries[i][1] + 1] - prefixSum[queries[i][0]];
}
return res;
}
};