
1.我的思路:枚举范围内的字符串
class Solution(object):
def vowelStrings(self, words, left, right):
"""
:type words: List[str]
:type left: int
:type right: int
:rtype: int
"""
count=0
list=['a','e','i','o','u']
for word in words[left:right+1]:
if word[0] in list and word[len(word)-1] in list:
count=count+1
return count
2.ai提醒
本质没有变换,但是简化了代码
class Solution(object):
def vowelStrings(self, words, left, right):
"""
:type words: List[str]
:type left: int
:type right: int
:rtype: int
"""
count=0
list1=['a','e','i','o','u']
result=list(filter(lambda word:word[0] in list1 and word[len(word)-1] in list1, words[left:right+1]))
return len(result)