LeetCode每日一题——2586. Count the Number of Vowel Strings in Range

文章目录

一、题目

You are given a 0-indexed array of string words and two integers left and right.

A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.

Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].

Example 1:

Input: words = ["are","amy","u"], left = 0, right = 2

Output: 2

Explanation:

  • "are" is a vowel string because it starts with 'a' and ends with 'e'.
  • "amy" is not a vowel string because it does not end with a vowel.
  • "u" is a vowel string because it starts with 'u' and ends with 'u'.
    The number of vowel strings in the mentioned range is 2.
    Example 2:

Input: words = ["hey","aeo","mu","ooo","artro"], left = 1, right = 4

Output: 3

Explanation:

  • "aeo" is a vowel string because it starts with 'a' and ends with 'o'.
  • "mu" is not a vowel string because it does not start with a vowel.
  • "ooo" is a vowel string because it starts with 'o' and ends with 'o'.
  • "artro" is a vowel string because it starts with 'a' and ends with 'o'.
    The number of vowel strings in the mentioned range is 3.

Constraints:

1 <= words.length <= 1000

1 <= words[i].length <= 10

words[i] consists of only lowercase English letters.

0 <= left <= right < words.length

二、题解

cpp 复制代码
class Solution {
public:
    int vowelStrings(vector<string>& words, int left, int right) {
        unordered_set<char> set = {'a','e','i','o','u'};
        int res = 0;
        for(int i = left;i <= right;i++){
            char front = words[i][0];
            char back = words[i].back();
            if(set.count(front) && set.count(back)) res++;
        }
        return res;
    }
};
相关推荐
森G19 小时前
五、Linux字符设备驱动
linux·arm开发·c++·ubuntu
云雾J视界19 小时前
深入浅出卷积神经网络(CNN):从LeNet到Vision Transformer的演进及其实战应用
面试·cnn·resnet·transformer·核心竞争力·认知升级·技术细节
繁星蓝雨19 小时前
我与C++的故事(杂谈)
开发语言·c++
白狐_79819 小时前
【项目实战】我用一个 HTML 文件写了一个“CET-6 单词斩”
前端·算法·html
Jasmine_llq19 小时前
《P3811 【模板】模意义下的乘法逆元》
数据结构·算法·线性求逆元算法·递推求模逆元
尋有緣19 小时前
力扣2292-连续两年有3个及以上的订单产品
leetcode·oracle·数据库开发
虹科网络安全20 小时前
艾体宝干货 | Redis Java 开发系列#2 数据结构
java·数据结构·redis
Jacob程序员20 小时前
欧几里得距离算法-相似度
开发语言·python·算法
ffcf20 小时前
消息中间件6:Redis副本数变为0和删除PVC的区别
算法·贪心算法
CoderYanger20 小时前
动态规划算法-斐波那契数列模型:2.三步问题
开发语言·算法·leetcode·面试·职场和发展·动态规划·1024程序员节