Add Biweekly 40

This commit is contained in:
YDZ
2020-11-29 20:20:08 +08:00
parent 9ac3fdeb96
commit efbd8e4156
4 changed files with 179 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package leetcode
import (
"strings"
)
func maxRepeating(sequence string, word string) int {
for i := len(sequence) / len(word); i >= 0; i-- {
tmp := ""
for j := 0; j < i; j++ {
tmp += word
}
if strings.Contains(sequence, tmp) {
return i
}
}
return 0
}

View File

@ -0,0 +1,53 @@
package leetcode
import (
"fmt"
"testing"
)
type question1665 struct {
para1665
ans1665
}
// para 是参数
// one 代表第一个参数
type para1665 struct {
sequence string
word string
}
// ans 是答案
// one 代表第一个答案
type ans1665 struct {
one int
}
func Test_Problem1665(t *testing.T) {
qs := []question1665{
{
para1665{"ababc", "ab"},
ans1665{2},
},
{
para1665{"ababc", "ba"},
ans1665{1},
},
{
para1665{"ababc", "ac"},
ans1665{0},
},
}
fmt.Printf("------------------------Leetcode Problem 1665------------------------\n")
for _, q := range qs {
_, p := q.ans1665, q.para1665
fmt.Printf("【input】:%v 【output】:%v \n", p, maxRepeating(p.sequence, p.word))
}
fmt.Printf("\n\n\n")
}