Skip to content

Commit 9bf9516

Browse files
committed
Fix(dp): fix wordBreak solution in dp
1 parent 82fc94d commit 9bf9516

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

basic_algorithm/dp.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,11 @@ func wordBreak(s string, wordDict []string) bool {
488488
f[0] = true
489489
max := maxLen(wordDict)
490490
for i := 1; i <= len(s); i++ {
491-
for j := i - max; j < i && j >= 0; j++ {
491+
l := 0
492+
if i - max > 0 {
493+
l = i - max
494+
}
495+
for j := l; j < i; j++ {
492496
if f[j] && inDict(s[j:i]) {
493497
f[i] = true
494498
break

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy