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)
相关推荐
多米Domi0111 分钟前
0x3f 第42天 复习 10:39-11:33
算法·leetcode
议题一玩到7 分钟前
#leetcode# 1984. Minimum Difference Between Highest and Lowest of K Scores
数据结构·算法·leetcode
喵手20 分钟前
Python爬虫零基础入门【第九章:实战项目教学·第2节】“接口优先“项目:从 Network 还原 JSON 接口分页!
爬虫·python·python爬虫实战·python爬虫工程化实战·python爬虫零基础入门·接口优先·json接口分页
将心ONE23 分钟前
QwenTTS 预设音色
python
冷雨夜中漫步43 分钟前
Python入门——字符串
开发语言·python
Yvonne爱编码44 分钟前
Java 接口学习核心难点深度解析
java·开发语言·python
漫随流水1 小时前
leetcode回溯算法(90.子集Ⅱ)
数据结构·算法·leetcode·回溯算法
June bug1 小时前
(#数组/链表操作)合并两个有重复元素的无序数组,返回无重复的有序结果
数据结构·python·算法·leetcode·面试·跳槽
普贤莲花1 小时前
取舍~2026年第4周小结---写于20260125
程序人生·算法·leetcode
人工智能AI技术1 小时前
【Agent从入门到实践】33 集成多工具,实现Agent的工具选择与执行
人工智能·python