leetcode_2586 统计范围元音字符串

1. 题意

元音字符串是首尾都是元音字母的字符串。
给字符数组,让你找出指定范围内的元音字符串的个数。
统计范围元音字符串

2. 题解

直接模拟即可

class Solution {
public:
    int vowelStrings(vector<string>& words, int left, int right) {
        
        unordered_set<int> us{'a','e','i','o','u'};
        int ans = 0;

        int sz = words.size();
        for ( int i = 0; i < sz; ++i) {
            if ( i >= left && i <= right) {

                int len = words[i].size();
                if (us.count(words[i][0]) && us.count(words[i][len - 1]))
                    ++ans;
            }
        }

        return ans;
    }
};

你可能感兴趣的:(leetcode,leetcode,算法,职场和发展)