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)
相关推荐
QQ14220784495 分钟前
IIS + wfastcgi 部署 Flask 应用实战:从连续 500 到稳定 200 的完整踩坑实录
python
WiKiLeaks_successor16 分钟前
Scipy库里的众数函数不严谨,我把它重构了。
python·scipy
傻啦嘿哟21 分钟前
房产数据对比爬虫:同时爬取链家+贝壳+安居客,做房价横向对比
python
6Hzlia25 分钟前
【Classic 150 刷题计划】 LeetCode 14. 最长公共前缀 | C++ 纵向扫描法与防越界细节
c++·算法·leetcode
小静AI工程实验室25 分钟前
JS 逆向接口 ID 变了?Python 与 Node.js 复现 JSON 大整数精度丢失
javascript·python·node.js
李航198328 分钟前
用 DeepDraw 几何引擎开发建筑设计软件(五):创建选择工具
python·3d
Metaphor69234 分钟前
使用 Python 设置 Excel 行列自适应 【代码示例】
python·excel
花酒锄作田9 小时前
FastAPI 使用 session 认证
python·fastapi
lsswear9 小时前
Python 并发 线程
开发语言·python
Ivanqhz10 小时前
MLIR OpBuilder
开发语言·python·mlir