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)
相关推荐
御承扬1 小时前
编程素养提升之EffectivePython(Builder篇)
python·设计模式·1024程序员节
chenchihwen2 小时前
AI代码开发宝库系列:FAISS向量数据库
数据库·人工智能·python·faiss·1024程序员节
AI视觉网奇3 小时前
json 可视化 2025 coco json
python·1024程序员节
mit6.8244 小时前
[nanoGPT] ChatGPT 的 LLM 的全栈实现 | 快速上手
python
DKunYu4 小时前
2.1线性回归
pytorch·python·深度学习·1024程序员节
大飞记Python4 小时前
实战分享:一键自动化下载指定版本的Chrome及Chromedriver(附Python源码)
chrome·python·自动化
Dream it possible!4 小时前
LeetCode 面试经典 150_链表_合并两个有序链表(58_21_C++_简单)
leetcode·链表·面试·1024程序员节
程序员杰哥5 小时前
如何使用Postman做接口自动化测试及完美的可视化报告?
自动化测试·软件测试·python·测试工具·jenkins·postman·1024程序员节
老歌老听老掉牙5 小时前
参数曲线切向量与叉乘向量的精确计算与分析
python·sympy·1024程序员节
Cherry Zack6 小时前
FastAPI 入门指南 :基础概念与核心特性
开发语言·python·fastapi·1024程序员节