mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-19 12:36:28 +08:00
Add Biweekly 40
This commit is contained in:
@ -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
|
||||
}
|
@ -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")
|
||||
}
|
Reference in New Issue
Block a user