<jupyter_start><jupyter_text>给定一个非空字符串s和一个包含非空单词列表的字典wordDict，    确定s是否可以被分割成一个由一个或多个字典单词组成的空格分隔序列。    注：词典中的同一个词在分词时可能会多次重复使用。你可以假设字典里没有重复的单词。        例1：        Input: s = "leetcode", wordDict = ["leet", "code"]        Output: true        Explanation: Return true because "leetcode" can be segmented as "leet code".        例2：        Input: s = "applepenapple", wordDict = ["apple", "pen"]        Output: true        Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".                     Note that you are allowed to reuse a dictionary word.    例3：         Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]         Output: false<jupyter_code>class Solution:
    def wordBreak(self, s: str, wordDict) -> bool:
        dp = [[False] * (len(s) + 1) for _ in range(len(wordDict) + 1)]
        for i in range(len(wordDict) + 1):
            for j in range(len(s) + 1):
                if (i == 0 and j == 0) or j == 0:
                    val = True
                else:
                    sub_s = s[:j]
                    sub_s_len = len(sub_s)
                    if sub_s in wordDict[:i]:
                        val = True and dp[i][j - sub_s_len]
                    else:
                        val = False
                dp[i][j] = val
        print(dp)
        return dp[-1][-1]
class Solution:
    def wordBreak(self, s: str, wordDict) -> bool:
        dp = [True]
        for i in range(1, len(s)+1):
            temp = False
            for j in range(i):
                sub_s = s[j:i]
                print(sub_s, i, j)
                if dp[j] and sub_s in wordDict:
                    temp = True
                    break
            dp += [temp]
        return dp[-1]
s_ = "leetcodeleet" 
wordDict_ = ["leet", "code"]
solution = Solution()
solution.wordBreak(s_, wordDict_)<jupyter_output>l 1 0
le 2 0
e 2 1
lee 3 0
ee 3 1
e 3 2
leet 4 0
leetc 5 0
eetc 5 1
etc 5 2
tc 5 3
c 5 4
leetco 6 0
eetco 6 1
etco 6 2
tco 6 3
co 6 4
o 6 5
leetcod 7 0
eetcod 7 1
etcod 7 2
tcod 7 3
cod 7 4
od 7 5
d 7 6
leetcode 8 0
eetcode 8 1
etcode 8 2
tcode 8 3
code 8 4
leetcodel 9 0
eetcodel 9 1
etcodel 9 2
tcodel 9 3
codel 9 4
odel 9 5
del 9 6
el 9 7
l 9 8
leetcodele 10 0
eetcodele 10 1
etcodele 10 2
tcodele 10 3
codele 10 4
odele 10 5
dele 10 6
ele 10 7
le 10 8
e 10 9
leetcodelee 11 0
eetcodelee 11 1
etcodelee 11 2
tcodelee 11 3
codelee 11 4
odelee 11 5
delee 11 6
elee 11 7
lee 11 8
ee 11 9
e 11 10
leetcodeleet 12 0
eetcodeleet 12 1
etcodeleet 12 2
tcodeleet 12 3
codeleet 12 4
odeleet 12 5
deleet 12 6
eleet 12 7
leet 12 8
{'fraction_non_alphanumeric': 0.08497489378138277, 'fraction_numerical': 0.07106991116261105, 'mean_word_length': 1.8182807399347116, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '174077', 'license': 'Apache-2.0', 'n_tokens_mistral': 1186, 'n_tokens_neox': 996, 'n_words': 378, 'path': 'Dynamic Programming/0730/139. Word Break.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '2589'}