0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: d = [False for _ in range(len(s)+1) ] d[0] = True wordSet = set(wordDict) for j in range(1,len(s)+1): for i in range(0,j+1): temp_word = s[i:j] if temp_word in wordSet and d[i]==True: d[j] = True print(d) return d[len(s)]
|