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)
相关推荐
人工干智能17 分钟前
爱因斯坦求和约定(Einstein Summation Convention)及einsum() 函数
python
YMWM_19 分钟前
查看realsense相机序列号脚本
开发语言·python·数码相机
lbb 小魔仙39 分钟前
Python 项目 CI/CD 实战:用 GitHub Actions 搭建自动化测试、覆盖率与发布流水线
python·ci/cd·github
西瓜太郎12341 小时前
request_id 如何串起请求、路由、计费和日志
后端·python
troy1281 小时前
Python 基础语法(一):变量、数据类型与运算符
java·服务器·python
用户298698530141 小时前
Python 将 Word 文档转换为图片的实践指南
后端·python·api
弈栈录1 小时前
LangChain Agent 实战:快速构建可调用工具的智能体
python·架构
宸津-代码粉碎机2 小时前
Spring AI 高危CVE漏洞深度复盘|生产禁跑版本汇总+临时防御+修复方案
java·大数据·人工智能·python·spring
承渊政道3 小时前
Python IDLE鸿蒙PC适配全记录:用 ArkUI 重建编辑、运行、Shell 与基础调试闭环
python·microsoft·harmonyos·鸿蒙系统·pc端
zjh9005303 小时前
Kotlin黑科技:空安全与Java兼容性深度解析
python