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)
相关推荐
hold?fish:palm15 小时前
20 旋转图像
c++·算法·leetcode
阿童木写作15 小时前
跨境卖家效率翻倍,跨马翻译批量图片翻译工具实测
人工智能·python
鹿鹿学长15 小时前
2026国赛报名季:从组委会第一次通知到各校8月报名通知,赛程报名评奖官方口径一次讲清
python·自动化
C++、Java和Python的菜鸟15 小时前
第15章 项目部署(Docker)
python
Jay-r15 小时前
极简博客搭建(精简版):textlog + GitHub Pages
python·github·教程·集成学习·博客网站·技术教程·自我成长
Albart57515 小时前
【已解决】IndexError_ list index out of range 列表索引越界 全套根治方案
python·indexerror·列表索引越界·python 报错解决·python 排错
卷心菜的学习路16 小时前
基于多模态向量检索的数学相似题推荐系统:完整设计、算法与实验
java·python·算法·大模型·推荐算法·数学相似题
小南知更鸟16 小时前
【leetcodehot100】leetcode-hot100-20260809更新
算法·leetcode·职场和发展
winfredzhang16 小时前
用 wxPython 打造「Claude Code 任务启动器」:一个把 AI CLI 变成一键工作流的桌面工具
python·wxpython·powershell·剪贴板·claudecodecli
Logintern0916 小时前
DeepAgents 的子 Agent 如何实现上下文隔离
python