题目描述
https://leetcode-cn.com/problems/word-break/
思路题解
dp:
https://leetcode-cn.com/problems/word-break/solution/dan-ci-chai-fen-by-leetcode-solution/
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
dp=[False]*(len(s)+1)
dp[0]=True
#dp不包含i,代表i之前的
for i in range(len(s)+1):
for j in range(i+1):
dp[i]=dp[i] or (dp[j] and s[j:i] in wordDict)
return dp[-1]