https://leetcode.cn/problems/word-break/description/?envType=study-plan-v2&envId=top-interview-150
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
n = len(s)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
for j in range(i):
if dp[j] and s[j:i] in wordDict:
dp[i] = True
break
return dp[n]
我發現本質就是如果前j個可以拼出來,j~i也可以拼出來,那麼前i個就都可以拼出來。到了第n個就做完了。