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

编程入门 行业动态 更新时间:2024-10-19 23:26:33

2586. 统计范围内的<a href=https://www.elefans.com/category/jswz/34/1696367.html style=元音字符串数"/>

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

题目

给你一个下标从 0 开始的字符串数组 words 和两个整数:left 和 right 。

如果字符串以元音字母开头并以元音字母结尾,那么该字符串就是一个 元音字符串 ,其中元音字母是 'a'、'e'、'i'、'o'、'u' 。

返回 words[i] 是元音字符串的数目,其中 i 在闭区间 [left, right] 内。

解题思路

  1. String类型自带前缀和后缀匹配方法;
  2. 通过自带的匹配方法进行逐个匹配寻找合适;

代码展示

class Solution {public int vowelStrings(String[] words, int left, int right) {int ans = 0;for (int i = left; i <= right; i++){if(words[i].startsWith("a") || words[i].startsWith("e") || words[i].startsWith("i") || words[i].startsWith("o") || words[i].startsWith("u") ){if(words[i].endsWith("a") || words[i].endsWith("e") || words[i].endsWith("i") || words[i].endsWith("o") || words[i].endsWith("u")){ans++;}}}return ans;}
}

更多推荐

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

本文发布于:2023-11-16 02:47:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1611682.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元音   范围内   字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!