Skip to content

Commit

Permalink
Create 0139-word-break.go
Browse files Browse the repository at this point in the history
  • Loading branch information
AP-Repositories authored Jan 5, 2023
1 parent 6528ac2 commit 96317a1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions go/0139-word-break.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
func wordBreak(s string, wordDict []string) bool {
dp := make([]bool, len(s) + 1)
dp[len(s)] = true

for i := len(s) - 1; i >= 0; i-- {
for _, w := range wordDict {
if (i + len(w)) <= len(s) && s[i : i + len(w)] == w {
dp[i] = dp[i + len(w)]
}
if dp[i] {
break
}
}
}
return dp[0]
}

0 comments on commit 96317a1

Please sign in to comment.