We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 1744c21 + 3223112 commit adaef1dCopy full SHA for adaef1d
problems/0139.单词拆分.md
@@ -344,6 +344,21 @@ func wordBreak(s string,wordDict []string) bool {
344
}
345
return dp[len(s)]
346
347
+// 转化为 求装满背包s的前几位字符的方式有几种
348
+func wordBreak(s string, wordDict []string) bool {
349
+ // 装满背包s的前几位字符的方式有几种
350
+ dp := make([]int, len(s)+1)
351
+ dp[0] = 1
352
+ for i := 0; i <= len(s); i++ { // 背包
353
+ for j := 0; j < len(wordDict); j++ { // 物品
354
+ if i >= len(wordDict[j]) && wordDict[j] == s[i-len(wordDict[j]):i] {
355
+ dp[i] += dp[i-len(wordDict[j])]
356
+ }
357
358
359
+
360
+ return dp[len(s)] > 0
361
+}
362
```
363
364
Javascript:
0 commit comments