add new solutions
This commit is contained in:
parent
9a10695e8c
commit
ca24d0a56a
30 changed files with 697 additions and 16 deletions
32
solutions/0/q97/solution.go
Normal file
32
solutions/0/q97/solution.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package q97
|
||||
|
||||
func isInterleave(s1 string, s2 string, s3 string) bool {
|
||||
if len(s1)+len(s2) != len(s3) {
|
||||
return false
|
||||
}
|
||||
|
||||
possible := make([][]bool, len(s1)+1)
|
||||
for i := range possible {
|
||||
possible[i] = make([]bool, len(s2)+1)
|
||||
}
|
||||
possible[0][0] = true
|
||||
|
||||
for tLen := 1; tLen <= len(s3); tLen++ {
|
||||
c := s3[tLen-1]
|
||||
for len1 := max(0, tLen-len(s2)); len1 <= min(len(s1), tLen); len1++ {
|
||||
len2 := tLen - len1
|
||||
|
||||
if len1 > 0 && s1[len1-1] == c && possible[len1-1][len2] {
|
||||
possible[len1][len2] = true
|
||||
continue
|
||||
}
|
||||
if len2 > 0 && s2[len2-1] == c && possible[len1][len2-1] {
|
||||
possible[len1][len2] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return possible[len(s1)][len(s2)]
|
||||
}
|
||||
|
||||
var _ = isInterleave
|
||||
Loading…
Add table
Add a link
Reference in a new issue