Skip to content

Commit

Permalink
Fix(dp): fix wordBreak solution in dp
Browse files Browse the repository at this point in the history
  • Loading branch information
FogDong committed Jul 2, 2020
1 parent 82fc94d commit 9bf9516
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion basic_algorithm/dp.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,11 @@ func wordBreak(s string, wordDict []string) bool {
f[0] = true
max := maxLen(wordDict)
for i := 1; i <= len(s); i++ {
for j := i - max; j < i && j >= 0; j++ {
l := 0
if i - max > 0 {
l = i - max
}
for j := l; j < i; j++ {
if f[j] && inDict(s[j:i]) {
f[i] = true
break
Expand Down

0 comments on commit 9bf9516

Please sign in to comment.