This is an O(n^3) solution requiring tabulation.
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
= set(wordDict)
wordSet = [1] + [0] * len(s)
dp for i in range(1, len(s)+1):
for j in range(i):
if dp[j] == 1 and s[j:i] in wordSet:
= 1
dp[i] break
return dp[-1] == 1