add new solutions
This commit is contained in:
parent
d798d5e8c9
commit
886b5e0a8e
34 changed files with 1164 additions and 0 deletions
28
solutions/1/q139/solution.go
Normal file
28
solutions/1/q139/solution.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package q139
|
||||
|
||||
func wordBreak(s string, wordDict []string) bool {
|
||||
possible := make([]bool, len(s)+1)
|
||||
possible[0] = true
|
||||
|
||||
for l := range possible {
|
||||
if !possible[l] {
|
||||
continue
|
||||
}
|
||||
for i := range wordDict {
|
||||
newLen := len(wordDict[i]) + l
|
||||
if newLen > len(s) {
|
||||
continue
|
||||
}
|
||||
if possible[newLen] {
|
||||
continue
|
||||
}
|
||||
if s[l:newLen] == wordDict[i] {
|
||||
possible[newLen] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return possible[len(s)]
|
||||
}
|
||||
|
||||
var _ = wordBreak
|
||||
Loading…
Add table
Add a link
Reference in a new issue