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)
相关推荐
weixin_3077791310 分钟前
用Python和FastAPI构建一个完整的企业级AI Agent微服务脚手架
python·fastapi·web app
熊猫_豆豆13 分钟前
回调函数的作用与举例(Python版)
服务器·python·编程语法
AI Echoes24 分钟前
LangChain 使用语义路由选择不同的Prompt模板
人工智能·python·langchain·prompt·agent
JJJJ_iii31 分钟前
【机器学习16】连续状态空间、深度Q网络DQN、经验回放、探索与利用
人工智能·笔记·python·机器学习·强化学习
CodeLongBear38 分钟前
从Java后端到Python大模型:我的学习转型与规划
java·python·学习
Miraitowa_cheems44 分钟前
LeetCode算法日记 - Day 94: 最长的斐波那契子序列的长度
java·数据结构·算法·leetcode·深度优先·动态规划
ada7_1 小时前
LeetCode(python)——49.字母异位词分组
java·python·leetcode
L_09071 小时前
【Algorithm】Day-11
c++·算法·leetcode
我的xiaodoujiao1 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 23--数据驱动--参数化处理 Yaml 文件
python·学习·测试工具·pytest
晨尘光1 小时前
【pycharm 创建一个线程,在线程函数中增加的日志打印,日志打印了,但是打断点进不去】
ide·python·pycharm