139. 单词拆分
首先要明确这个是求排列数,所以是先遍历背包,再遍历物品。
func wordBreak(s string, wordDict []string) bool {
dp := make([]bool, len(s) + 1)
dp[0] = true
for j := 1; j <= len(s); j++{
for i := 0; i < len(wordDict); i++{
if j - len(wordDict[i]) >= 0 && dp[j - len(wordDict[i])] == true && wordDict[i] == s[(j - len(wordDict[i])) : j]{
dp[j] = true
}
}
}
return dp[len(s)]
}