Skip to content

Commit 96317a1

Browse files
Create 0139-word-break.go
Accepted submission: _https://leetcode.com/submissions/detail/872095387/_
1 parent 6528ac2 commit 96317a1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

go/0139-word-break.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func wordBreak(s string, wordDict []string) bool {
2+
dp := make([]bool, len(s) + 1)
3+
dp[len(s)] = true
4+
5+
for i := len(s) - 1; i >= 0; i-- {
6+
for _, w := range wordDict {
7+
if (i + len(w)) <= len(s) && s[i : i + len(w)] == w {
8+
dp[i] = dp[i + len(w)]
9+
}
10+
if dp[i] {
11+
break
12+
}
13+
}
14+
}
15+
return dp[0]
16+
}

0 commit comments

Comments
 (0)