Untitled
unknown
plain_text
6 months ago
882 B
8
Indexable
class Solution { public: bool isLowercaseVowel(int c){ return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); } vector<int> vowelStrings(vector<string>& words, vector<vector<int>>& queries) { int n = words.size(); vector < int > cumulative(n+1, 0); vector < int > ans(queries.size(),0); for(int i=0;i<n;i++) { int m = words[i].size(); int prev = max(i, 0); if(isLowercaseVowel(words[i][0]) && isLowercaseVowel(words[i][m-1])) { cumulative[i+1] = cumulative[prev] + 1; } else { cumulative[i+1] = cumulative[prev]; } } for(int i=0;i<queries.size();i++) { int l = queries[i][0] , r = queries[i][1]; ans[i] = (cumulative[r+1] - cumulative[l]); } return ans; } };
Editor is loading...
Leave a Comment