We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 82fc94d commit 9bf9516Copy full SHA for 9bf9516
1 file changed
basic_algorithm/dp.md
@@ -488,7 +488,11 @@ func wordBreak(s string, wordDict []string) bool {
488
f[0] = true
489
max := maxLen(wordDict)
490
for i := 1; i <= len(s); i++ {
491
- for j := i - max; j < i && j >= 0; j++ {
+ l := 0
492
+ if i - max > 0 {
493
+ l = i - max
494
+ }
495
+ for j := l; j < i; j++ {
496
if f[j] && inDict(s[j:i]) {
497
f[i] = true
498
break
0 commit comments