Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8723380

Browse files
Merge pull request greyireland#15 from FogDong/master
Fix(dp): fix wordBreak solution in dp
2 parents 82fc94d + 9bf9516 commit 8723380

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)

AltStyle によって変換されたページ (->オリジナル) /