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)
相关推荐
素玥14 小时前
实训7 json文件数据用python导入数据库
数据库·python·json
千枫s14 小时前
做一个电脑版爬虫程序
爬虫·python
大邳草民14 小时前
Python 对象模型与属性访问机制
开发语言·笔记·python
weixin_4024863414 小时前
小分子 pdb准化为sdf
python
橘子编程14 小时前
密码学完全指南:从基础到实战
java·python·密码学
蓝色的杯子14 小时前
Python面试30分钟突击掌握-LeetCode2-Strings
python
ZC跨境爬虫14 小时前
海南大学交友平台开发实战 day9(头像上传存入 SQLite+BLOB 存储 + 前后端联调避坑全记录)
前端·数据库·python·sqlite
FreakStudio14 小时前
嘉立创开源:应该是全网MicroPython教程最多的开发板
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy
上天_去_做颗惺星 EVE_BLUE14 小时前
接口自动化测试全流程:pytest 用例收集、并行执行、Allure 报告合并与上传
python·pytest
chushiyunen14 小时前
python fastapi使用、uvicorn
开发语言·python·fastapi