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;
    }
};
相关推荐
田里的水稻6 分钟前
C++_python_相互之间的包含调用方法
c++·chrome·python
sinat_2869451911 分钟前
opencode
人工智能·算法·chatgpt
HABuo18 分钟前
【Linux进程(四)】进程切换&环境变量深入剖析
linux·运维·服务器·c语言·c++·ubuntu·centos
工口发动机27 分钟前
ABC440DEF简要题解
c++·算法
带土133 分钟前
4. C++ static关键字
开发语言·c++
橘颂TA34 分钟前
【Linux】死锁四条件的底层逻辑:从锁冲突到 STL 组件的线程安全实践(Ⅵ)
linux·运维·服务器·c++·死锁
C++ 老炮儿的技术栈40 分钟前
什么是通信规约
开发语言·数据结构·c++·windows·算法·安全·链表
零小陈上(shouhou6668889)1 小时前
K-近邻算法 - lazy learning的代表
算法·近邻算法
学历真的很重要1 小时前
LangChain V1.0 Context Engineering(上下文工程)详细指南
人工智能·后端·学习·语言模型·面试·职场和发展·langchain
有一个好名字1 小时前
力扣-从字符串中移除星号
java·算法·leetcode