统计范围内的元音字符串数【2586】
给你一个下标从 0 开始的字符串数组
words和两个整数:left和right。如果字符串以元音字母开头并以元音字母结尾,那么该字符串就是一个 元音字符串 ,其中元音字母是
'a'、'e'、'i'、'o'、'u'。返回
words[i]是元音字符串的数目,其中i在闭区间[left, right]内。
之后请假啦,有更重要的事情要去做,题继续刷,题解写不写啦
-
思路
判断在闭区间
[left, right]内的单词是否是元音字符串,记录是元音字符串的个数 -
实现
class Solution { public int vowelStrings(String[] words, int left, int right) { int res = 0; while (left <= right){ String word = words[left]; if (isVowel(word, 0) && isVowel(word, word.length() - 1)){ res++; } left++; } return res; } public boolean isVowel(String word, int index){ char c = word.charAt(index); if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){ return true; } return false; } }- 复杂度
- 时间复杂度:O(n)O(n)O(n)
- 空间复杂度:O(1)O(1)O(1)
- 复杂度

代码解决如何在给定字符串数组中,根据指定左右边界统计以元音开头和结尾的单词数量,使用O(n)时间复杂度
1128

被折叠的 条评论
为什么被折叠?



