LeetCode.139 单词拆分
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
dp = [0] * (len(s)+1)
dp[0] = 1
for start in range(len(dp)):
for end in range(start+1, len(dp)):
if dp[start] and s[start:end] in wordDict:
dp[end] = 1
return bool(dp[-1])