2559.cpp (716B)
1 class Solution { 2 static bool is_vowel(const char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; } 3 4 public: 5 vector<int> vowelStrings(const vector<string> &words, const vector<vector<int>> &queries) const { 6 static int count[100002]; 7 const int n = size(words), m = size(queries); 8 9 memset(count, 0x00, sizeof(count)); 10 for (int i = 0, acc = 0; i < n; i++) { 11 if (is_vowel(words[i].front()) && is_vowel(words[i].back())) acc++; 12 count[i + 1] = acc; 13 } 14 15 vector<int> res(m); 16 for (int i = 0; i < m; i++) { 17 res[i] = count[queries[i][1] + 1] - count[queries[i][0]]; 18 } 19 return res; 20 } 21 };