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)
相关推荐
_oP_i3 小时前
python 后缀 mjs文件
开发语言·python
北斗落凡尘3 小时前
如何使用LangGraph(1)
python·langchain
Livia要学习4 小时前
Python装饰器
开发语言·python
evans在进步5 小时前
LeetCode 200:岛屿数量——Java DFS 染色法详解
java·leetcode·深度优先
circuitsosk5 小时前
向量数据库选型与性能压测:Milvus、Pinecone、Chroma在真实业务下的对比
数据库·python·pinecone·milvus·向量数据库·chroma
旖旎夜光5 小时前
LeetCode 202:快乐数(双指针问题) —— 题解
数据结构·c++·算法·leetcode·双指针
雾时之林5 小时前
python--字符串
开发语言·python
战略性的菠萝5 小时前
研究生基本功-Python快速入门(一)
python
鬼手点金6 小时前
与LLM结合的主流智能爬虫框架
爬虫·python·llm·post·request·firecrawl·crawl4ai
月光船幽幽6 小时前
门控函数SHS阈值与调制机制解析
人工智能·python·算法