classSolution(object): defwordBreak(self, s, wordDict): """ :type s: str :type wordDict: List[str] :rtype: bool """ d = {} dp = [False]*len(s) for word in wordDict: if word notin d: d[word] = 1 dp[0] = Trueif s[0] in d elseFalse for i in range(1,len(s)): if s[:i+1] in d: dp[i] = True continue for j in range(i): if dp[j] and s[j+1:i+1] in d: dp[i] = True break return dp[-1]