2586_CounttheNumberofVowelStringsinRange - a920604a/leetcode GitHub Wiki


categories: leetcode comments: false title: 2586. Count the Number of Vowel Strings in Range

solution

class Solution {
public:
    unordered_set<char> vowels = {'a','e','i', 'o','u'};
    bool isValid(string word) {
        return vowels.count(word.front()) && vowels.count(word.back());
    }
    int vowelStrings(vector<string>& words, int left, int right) {
        int count = 0;
        for(int i=left ; i<=right ; ++i) {
            if(isValid(words[i])) count++;
        }
        return count;
    }
};

analysis

  • time complexity O(n)
  • space complexity O(1)
⚠️ **GitHub.com Fallback** ⚠️