139. Word Break

139. Word Break

python 复制代码
import copy
class Solution:

    def wordBreak(self, s: str, wordDict: List[str]) -> bool:
        dp =[0 for i in range(len(s)+1)]
        words=set(wordDict)
        dp[0]=1
        for i in range(1,len(s)+1):
            for j in range(i-1,-1,-1):
                if dp[j]==0:continue
                if s[j:i] in words:
                    dp[i]=1
                    break
        return dp[len(s)]
相关推荐
爱编程的化学家13 小时前
代码随想录算法训练营第六天 - 哈希表2 || 454.四数相加II / 383.赎金信 / 15.三数之和 / 18.四数之和
数据结构·c++·算法·leetcode·双指针·哈希
芒克芒克20 小时前
LeetCode 面试经典 150 题:多数元素(摩尔投票法详解 + 多解法对比)
算法·leetcode·面试
ゞ 正在缓冲99%…1 天前
leetcode438.找到字符串中所有字母异位词
leetcode·滑动窗口
pzx_0011 天前
【LeetCode】392.判断子序列
算法·leetcode·职场和发展
iナナ1 天前
Java优选算法——二分查找
数据结构·算法·leetcode
Adorable老犀牛1 天前
阿里云-基于通义灵码实现高效 AI 编码 | 8 | 上手实操:LeetCode学习宝典,通义灵码赋能算法高效突破
学习·算法·leetcode
林木辛1 天前
LeetCode 热题 160.相交链表(双指针)
算法·leetcode·链表
崎岖Qiu1 天前
leetcode380:RandomizedSet - O(1)时间插入删除和获取随机元素(数组+哈希表的巧妙结合)
java·数据结构·算法·leetcode·力扣·散列表
好易学·数据结构1 天前
可视化图解算法60: 矩阵最长递增路径
数据结构·算法·leetcode·力扣·递归·回溯算法·牛客
大锦终1 天前
【算法】栈专题
数据结构·c++·算法·leetcode