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)
相关推荐
Navigator_Z19 分钟前
LeetCode //C - 1240. Tiling a Rectangle with the Fewest Squares
c语言·算法·leetcode
稻米哟19 分钟前
力扣100——双指针
算法·leetcode
2601_9620994642 分钟前
Python中的find()函数:用法和示例
python·字符串·索引·子字符串·find函数
大圣编蚕1 小时前
Java StringWriter 详解:从入门到实战
java·开发语言·python
for_ever_love__2 小时前
python基础语法学习: requirements.txt
开发语言·python·学习
程序员清风2 小时前
FastAPI 入门:用 Python 快速开发现代后端服务
python·oracle·fastapi
SunnyDays10112 小时前
使用 Python 提取 Word 文档中的表格数据
python·word
for_ever_love__2 小时前
python基础语法学习: 动态类型
开发语言·python·学习
troy1283 小时前
分布式系统框架选型指南:主流框架优缺点深度对比
python·django·pygame
129Lab3 小时前
BMS算法快速原型开发:AI辅助实现扩展卡尔曼滤波(EKF)SOC估算从理论到代码落地
python·嵌入式开发·bms·卡尔曼滤波·电池管理系统·soc估算