Skip to content

Commit efbd8e4

Browse files
committed
Add Biweekly 40
1 parent 9ac3fde commit efbd8e4

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package leetcode
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func maxRepeating(sequence string, word string) int {
8+
for i := len(sequence) / len(word); i >= 0; i-- {
9+
tmp := ""
10+
for j := 0; j < i; j++ {
11+
tmp += word
12+
}
13+
if strings.Contains(sequence, tmp) {
14+
return i
15+
}
16+
}
17+
return 0
18+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package leetcode
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
type question1665 struct {
9+
para1665
10+
ans1665
11+
}
12+
13+
// para 是参数
14+
// one 代表第一个参数
15+
type para1665 struct {
16+
sequence string
17+
word string
18+
}
19+
20+
// ans 是答案
21+
// one 代表第一个答案
22+
type ans1665 struct {
23+
one int
24+
}
25+
26+
func Test_Problem1665(t *testing.T) {
27+
28+
qs := []question1665{
29+
30+
{
31+
para1665{"ababc", "ab"},
32+
ans1665{2},
33+
},
34+
35+
{
36+
para1665{"ababc", "ba"},
37+
ans1665{1},
38+
},
39+
40+
{
41+
para1665{"ababc", "ac"},
42+
ans1665{0},
43+
},
44+
}
45+
46+
fmt.Printf("------------------------Leetcode Problem 1665------------------------\n")
47+
48+
for _, q := range qs {
49+
_, p := q.ans1665, q.para1665
50+
fmt.Printf("【input】:%v 【output】:%v \n", p, maxRepeating(p.sequence, p.word))
51+
}
52+
fmt.Printf("\n\n\n")
53+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package leetcode
2+
3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// ListNode define
8+
type ListNode = structures.ListNode
9+
10+
/**
11+
* Definition for singly-linked list.
12+
* type ListNode struct {
13+
* Val int
14+
* Next *ListNode
15+
* }
16+
*/
17+
18+
func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *ListNode {
19+
pre, cur, list2Cur := list1, list1.Next, list2
20+
for cur.Next != nil {
21+
if cur.Val == a {
22+
pre.Next = list2
23+
pre = cur
24+
break
25+
}
26+
pre = cur
27+
cur = cur.Next
28+
}
29+
cur = cur.Next
30+
for list2Cur.Next != nil {
31+
list2Cur = list2Cur.Next
32+
}
33+
if a == b {
34+
list2Cur.Next = cur
35+
return list1
36+
}
37+
for cur.Next != nil {
38+
if cur.Val == b {
39+
list2Cur.Next = cur.Next
40+
break
41+
}
42+
pre = cur
43+
cur = cur.Next
44+
}
45+
return list1
46+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package leetcode
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
8+
)
9+
10+
type question2 struct {
11+
para2
12+
ans2
13+
}
14+
15+
// para 是参数
16+
// one 代表第一个参数
17+
type para2 struct {
18+
one []int
19+
a int
20+
b int
21+
another []int
22+
}
23+
24+
// ans 是答案
25+
// one 代表第一个答案
26+
type ans2 struct {
27+
one []int
28+
}
29+
30+
func Test_Problem2(t *testing.T) {
31+
32+
qs := []question2{
33+
34+
{
35+
para2{[]int{0, 1, 2, 3, 4, 5}, 3, 4, []int{1000000, 1000001, 1000002}},
36+
ans2{[]int{0, 1, 2, 1000000, 1000001, 1000002, 5}},
37+
},
38+
39+
{
40+
para2{[]int{0, 1, 2, 3, 4, 5, 6}, 2, 5, []int{1000000, 1000001, 1000002, 1000003, 1000004}},
41+
ans2{[]int{0, 1, 1000000, 1000001, 1000002, 1000003, 1000004, 6}},
42+
},
43+
44+
{
45+
para2{[]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 3, 5, []int{1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006}},
46+
ans2{[]int{0, 1, 2, 1000000, 1000001, 1000002, 1000003, 1000004, 1000005, 1000006, 6, 7, 8, 9}},
47+
},
48+
49+
{
50+
para2{[]int{0, 1, 2}, 1, 1, []int{1000000, 1000001, 1000002, 1000003}},
51+
ans2{[]int{0, 1000000, 1000001, 1000002, 1000003, 2}},
52+
},
53+
}
54+
55+
fmt.Printf("------------------------Leetcode Problem 2------------------------\n")
56+
57+
for _, q := range qs {
58+
_, p := q.ans2, q.para2
59+
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(mergeInBetween(structures.Ints2List(p.one), p.a, p.b, structures.Ints2List(p.another))))
60+
}
61+
fmt.Printf("\n\n\n")
62+
}

0 commit comments

Comments
 (0)