Python | Leetcode Python题解之第139题单词拆分

题目:

题解:

python 复制代码
class Solution:
    def wordBreak(self, s: str, wordDict: List[str]) -> bool:
        import functools
        @functools.lru_cache(None)
        def back_track(s):
            if(not s):
                return True
            res=False
            for i in range(1,len(s)+1):
                if(s[:i] in wordDict):
                    res=back_track(s[i:]) or res
            return res
        return back_track(s)
相关推荐
深蓝电商API11 分钟前
Scrapy爬虫限速与并发控制最佳实践
爬虫·python·scrapy
Derrick__112 分钟前
淘宝MD5爬虫
爬虫·python
薛定谔的猫198215 分钟前
llama-index Embedding 落地到 RAG 系统
开发语言·人工智能·python·llama-index
夏鹏今天学习了吗17 分钟前
【LeetCode热题100(78/100)】爬楼梯
算法·leetcode·职场和发展
圣保罗的大教堂22 分钟前
leetcode 712. 两个字符串的最小ASCII删除和 中等
leetcode
nimadan122 小时前
**手机小说扫榜工具2025推荐,精准追踪榜单动态与题材风向
python·智能手机
编程武士2 小时前
Python 各版本主要变化速览
开发语言·python
傻啦嘿哟2 小时前
Python中的@property:优雅控制类成员访问的魔法
前端·数据库·python
sky17203 小时前
VectorStoreRetriever 三种搜索类型
python·langchain
旦莫3 小时前
Python测试开发工具库:日志脱敏工具(敏感信息自动屏蔽)
python·测试开发·自动化·ai测试