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

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)
相关推荐
geovindu1 小时前
rust: Timing Functions Pattern
开发语言·后端·设计模式·rust·计时函数模式·性能分析型模式
geovindu2 小时前
python:Lasso
开发语言·后端·python·算法
多加点辣也没关系2 小时前
JavaScript|第42章:安全与最佳实践
开发语言·javascript·安全
3095566662 小时前
股票数据落库前的去重与主键设计:一次 SQLite 写入实录
java·开发语言·jvm·数据库·redis·python·sqlite
利威尔xu3 小时前
2026-11-19-Go反射为什么慢面试
开发语言·面试·golang
山楂树の4 小时前
Python 函数:参数、作用域、Lambda 与类型注解
开发语言·python
旖旎夜光4 小时前
【C 语言】(一)(下)指针进阶:const、二级指针、函数指针与指针题
c语言·开发语言·笔记·学习
炸薯条!4 小时前
Python装饰器详解:从闭包原理到语法糖,再到多个装饰器
开发语言·python
星落梦生4 小时前
苍穹外卖day3——阿里云oss文件上传
java·开发语言
Risehuxyc5 小时前
PHP函数注释怎么写
开发语言·php