题目
给你一个下标从 0 开始的字符串数组 words 和两个整数:left 和 right 。
如果字符串以元音字母开头并以元音字母结尾,那么该字符串就是一个 元音字符串 ,其中元音字母是 'a'、'e'、'i'、'o'、'u' 。
返回 words[i] 是元音字符串的数目,其中 i 在闭区间 [left, right] 内。
解题思路
- String类型自带前缀和后缀匹配方法;
- 通过自带的匹配方法进行逐个匹配寻找合适;
代码展示
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;}
}