力扣 2586. 统计范围内的元音字符串数

题目来源:https://leetcode.cn/problems/count-the-number-of-vowel-strings-in-range/

力扣 2586. 统计范围内的元音字符串数_第1张图片

C++题解:将words中的字符串一个一个的取出来,再判断每个字符串中首字符和尾字符是否为元音字母。

class Solution {
public:
    int vowelStrings(vector& words, int left, int right) {
        int len = words.size();
        string tem;
        int num = 0, a = 0;
        string sets = {'a','o','e','i','u'};
        for(int ii = left; ii <= right; ii++){
            tem = words[ii];
            a = tem.size()-1;
            if((sets.find(tem[0])<=4)&&(sets.find(tem[a])<=4))  num++;
        }
        return num;
    }
};

你可能感兴趣的:(开始C++吧,leetcode,c++)