leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2559.cpp (716B)
0 class Solution { 1 static bool is_vowel(const char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; } 2 3 public: 4 vector<int> vowelStrings(const vector<string> &words, const vector<vector<int>> &queries) const { 5 static int count[100002]; 6 const int n = size(words), m = size(queries); 7 8 memset(count, 0x00, sizeof(count)); 9 for (int i = 0, acc = 0; i < n; i++) { 10 if (is_vowel(words[i].front()) && is_vowel(words[i].back())) acc++; 11 count[i + 1] = acc; 12 } 13 14 vector<int> res(m); 15 for (int i = 0; i < m; i++) { 16 res[i] = count[queries[i][1] + 1] - count[queries[i][0]]; 17 } 18 return res; 19 } 20 };