add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent d798d5e8c9
commit 886b5e0a8e
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
34 changed files with 1164 additions and 0 deletions

View 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