查分单词-Python

问题:

# 给定一个非空字符串 s 和一个包含非空单词的列表 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。 
#
# 说明:
#
#
# 拆分时可以重复使用字典中的单词。
# 你可以假设字典中没有重复的单词。
#
def wordBreak(s, wordDict):
    n = len(s)
    dp = [False] * (n+1)
    dp[0] = True
    for i in range(n):
        for j in range(i+1, n+1):
            if dp[i] and s[i:j] in wordDict:
                dp[j] = True
    return dp[-1]
时刻记着自己要成为什么样的人!
原文地址:https://www.cnblogs.com/demo-deng/p/15248327.html