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)
相关推荐
如竟没有火炬19 小时前
有序矩阵中第K小的元素
数据结构·线性代数·算法·leetcode·矩阵·深度优先
AI玫瑰助手19 小时前
Python函数:def定义函数与参数传递基础
android·开发语言·python
24kmaigc19 小时前
NewStarCTF2025-ssti在哪里?-ssrf与ssti注入
python·网络安全·flask·web
老虎海子19 小时前
从零手搓一个 AI 编程助手:Mini Claude Code 完全指南
人工智能·git·vscode·python·github
洛水水19 小时前
【力扣100题】63.最小覆盖子串
算法·leetcode
辞忧九千七20 小时前
吃透Redis7核心数据结构:从基础用法到实战场景(Python版)
开发语言·数据结构·redis·python
空圆小生20 小时前
基于 Python+Vue3 的 AI 人脸识别门禁考勤系统
开发语言·人工智能·python
Yoshizawa-Violet20 小时前
模板方法模式实战:重构Agent工具审批,告别重复代码
python·agent·模板方法
HjhIron20 小时前
Python列表与LLM接口实战:从切片到DeepSeek调用
python
搬砖的小码农_Sky20 小时前
macOS Sequoia上如何安装Python开发环境?
开发语言·python·macos