[LeetCode]--139. Word Break(Python)
来源:互联网 发布:北京网库 知乎 编辑:程序博客网 时间:2024/06/06 15:49
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
For example, given
s = "leetcode",dict = ["leet", "code"].
Return true because "leetcode"
can be segmented as "leet code"
.
Subscribe to see which companies asked this question
Let’s see the Python Code
Extremely Concise
class Solution(object): def wordBreak(self, s, wordDict): """ :type s: str :type wordDict: Set[str] :rtype: bool """ # dp[i] = true means that s[0, i -1] can be constructed by the words in wordDict. # So, dp[0] must be ture. n, dp = len(s), [True] + [False] * len(s) for i in range(n): for j in range(i + 1): if dp[j] and s[j:i+1] in wordDict: dp[i + 1] = True break return dp[n]
0 0
- [LeetCode]--139. Word Break(Python)
- [Leetcode][python]Word Break/Word Break II
- 【leetcode】Word Break(python)
- LeetCode--Word Break(分词)Python
- LeetCode 139. Word Break
- [LeetCode]139.Word Break
- [leetcode] 139.Word Break
- leetcode 139. Word Break
- [LeetCode]139. Word Break
- 139. Word Break LeetCode
- LeetCode-139.Word Break
- LeetCode *** 139. Word Break
- LeetCode 139. Word Break
- LeetCode 139. Word Break
- [leetcode] 139. Word Break
- [leetcode] 139. Word Break
- [LeetCode] 139. Word Break
- [leetcode]139. Word Break
- addShutdownHook+ @Scheduled(cron = "0 0/1 * * ?" )
- 调整数据库栏位的位置
- 【华为 OJ 】合法IP
- [USACO Training] Section 1.3
- CSU-ACM2016暑假集训比赛8
- [LeetCode]--139. Word Break(Python)
- c/c++第十一天
- web项目重名称之后无法启动
- java 日期和时间
- jquery源码资料收集
- (五)maven核心概念
- struts2 exp S2-016
- POJ 1042 Gone Fishing 贪心 枚举
- 【数据结构】压缩特殊矩阵