Skip to content

Commit eef67b3

Browse files
committed
feat(/) :daiyl update
1 parent c4ce228 commit eef67b3

File tree

8 files changed

+87
-30
lines changed

8 files changed

+87
-30
lines changed

src/0021.Merge-Two-Sorted-Lists/Solution.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package Solution
22

3+
type ListNode struct {
4+
Val int
5+
Next *ListNode
6+
}
7+
38
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
49
head := &ListNode{}
510
tmp := head
@@ -22,8 +27,3 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
2227

2328
return head.Next
2429
}
25-
26-
type ListNode struct {
27-
Val int
28-
Next *ListNode
29-
}

src/0025.Reverse-Nodes-in-k-Group/Solution_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ func TestSolution(t *testing.T) {
1212
input2 int
1313
expect *ListNode
1414
}{
15-
{"TestCacse 1", UnmarshalListBySlice([]int{1, 2, 3, 4, 5}), 2, UnmarshalListBySlice([]int{2, 1, 4, 3, 5})},
16-
{"TestCacse 2", UnmarshalListBySlice([]int{1, 2, 3, 4, 5}), 3, UnmarshalListBySlice([]int{3, 2, 1, 4, 5})},
15+
{
16+
"TestCacse 1",
17+
UnmarshalListBySlice([]int{1, 2, 3, 4, 5}),
18+
2,
19+
UnmarshalListBySlice([]int{2, 1, 4, 3, 5})},
20+
{
21+
"TestCacse 2",
22+
UnmarshalListBySlice([]int{1, 2, 3, 4, 5}),
23+
3,
24+
UnmarshalListBySlice([]int{3, 2, 1, 4, 5}),
25+
},
1726
}
1827

1928
// 开始测试

src/0026.Remove-Duplicates-from-Sorted-Array/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ for (int i = 0; i < len; i++) {
4949

5050
## 题解
5151
### 思路1
52-
题意是让你从一个有序的数组中移除重复的元素,并返回之后数组的长度。我的思路是判断长度小于等于 1 的话直接返回原长度即可,否则的话遍历一遍数组,用一个 `tail` 变量指向尾部,如果后面的元素和前面的元素不同,就让 `tail` 变量加一,最后返回 `tail` 即可。
52+
> 题意是让你从一个有序的数组中移除重复的元素,并返回之后数组的长度。我的思路是判断长度小于等于 1
53+
的话直接返回原长度即可,否则的话遍历一遍数组,用一个 `tail` 变量指向尾部,如果后面的元素和前面的元素不同,
54+
就让 `tail` 变量加一,最后返回 `tail` 即可。
5355
```go
5456
func removeDuplicates(nums []int) int {
5557
if len(nums) <= 1 {
Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,50 @@
11
package Solution
22

3+
import "math"
4+
35
func divide(dividend int, divisor int) int {
4-
return 0
6+
dm, dsm, sign := true, true, true
7+
if dividend < 0 {
8+
dm = false
9+
dividend = -dividend
10+
}
11+
if divisor < 0 {
12+
dsm = false
13+
divisor = -divisor
14+
}
515

6-
}
7-
func Abs(x int) int {
8-
if x > 0 {
9-
return x
16+
if (dm && !dsm) || (!dm && dsm) {
17+
sign = false
18+
}
19+
20+
if divisor == 0 {
21+
return math.MaxInt32
22+
}
23+
24+
h := 0
25+
out := 0
26+
if dividend < divisor {
27+
return 0
28+
}
29+
for (divisor << uint(h)) <= dividend {
30+
h++
31+
}
32+
h--
33+
for i := h; i >= 0; i-- {
34+
if dividend >= (divisor << uint(i)) {
35+
dividend -= (divisor << uint(i))
36+
out |= 1 << uint(i)
37+
}
38+
}
39+
40+
if !sign {
41+
out = -out
42+
}
43+
if out > math.MaxInt32 {
44+
return math.MaxInt32
45+
} else if out < math.MinInt32 {
46+
return math.MinInt32
47+
} else {
48+
return out
1049
}
11-
return -x
1250
}

src/0029.Divide-Two-Integers/Solution_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ func TestSolution(t *testing.T) {
99
// 测试用例
1010
cases := []struct {
1111
name string
12-
inputs bool
13-
expect bool
12+
inputs []int
13+
expect int
1414
}{
15-
{"1 test 1", true, true},
16-
{"2 test 2", true, true},
17-
{"3 test 3", false, true},
15+
{"1 test 1", []int{10, 3}, 3},
16+
{"1 test 2", []int{7, -3}, -2},
1817
}
1918

2019
// 开始测试
2120
for _, c := range cases {
2221
t.Run(c.name, func(t *testing.T) {
23-
ret := Solution(c.inputs)
22+
ret := divide(c.inputs[0], c.inputs[1])
2423
if !reflect.DeepEqual(ret, c.expect) {
2524
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
2625
c.expect, ret, c.inputs)

src/0030.Substring-with-Concatenation-of-All-Words/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Output: "10101"
2323
**Tags:** Math, String
2424

2525
## 题意
26-
>给你两个二进制串,求其和的二进制串。
26+
>给定一个目标字符串s,一个单词集合words。
27+
要求使得words集合中所有元素连续出现在s中的首位置组成的集合(元素顺序不考虑)。
2728

2829
## 题解
2930

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func findSubstring(s string, words []string) []int {
4+
55
}

src/0030.Substring-with-Concatenation-of-All-Words/Solution_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@ func TestSolution(t *testing.T) {
99
// 测试用例
1010
cases := []struct {
1111
name string
12-
inputs bool
13-
expect bool
12+
input1 string
13+
input2 []string
14+
expect []int
1415
}{
15-
{"TestCacse 1", true, true},
16-
{"TestCacse 1", true, true},
17-
{"TestCacse 1", false, true},
16+
{"TestCacse 1",
17+
"barfoothefoobarman",
18+
[]string{"foo", "bar"},
19+
[]int{0, 9},
20+
},
21+
{"TestCacse 2",
22+
"wordgoodstudentgoodword",
23+
[]string{"word", "student"},
24+
[]int{},
25+
},
1826
}
1927

2028
// 开始测试
2129
for _, c := range cases {
2230
t.Run(c.name, func(t *testing.T) {
23-
ret := Solution(c.inputs)
31+
ret := findSubstring(c.input1, c.input2)
2432
if !reflect.DeepEqual(ret, c.expect) {
2533
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
26-
c.expect, ret, c.inputs)
34+
c.expect, ret, c.input1)
2735
}
2836
})
2937
}

0 commit comments

Comments
 (0)