Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteef67b3

Browse files
committed
feat(/) :daiyl update
1 parentc4ce228 commiteef67b3

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+
typeListNodestruct {
4+
Valint
5+
Next*ListNode
6+
}
7+
38
funcmergeTwoLists(l1*ListNode,l2*ListNode)*ListNode {
49
head:=&ListNode{}
510
tmp:=head
@@ -22,8 +27,3 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
2227

2328
returnhead.Next
2429
}
25-
26-
typeListNodestruct {
27-
Valint
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
input2int
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
funcremoveDuplicates(nums []int)int {
5557
iflen(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
funcdivide(dividendint,divisorint)int {
4-
return0
6+
dm,dsm,sign:=true,true,true
7+
ifdividend<0 {
8+
dm=false
9+
dividend=-dividend
10+
}
11+
ifdivisor<0 {
12+
dsm=false
13+
divisor=-divisor
14+
}
515

6-
}
7-
funcAbs(xint)int {
8-
ifx>0 {
9-
returnx
16+
if (dm&&!dsm)|| (!dm&&dsm) {
17+
sign=false
18+
}
19+
20+
ifdivisor==0 {
21+
returnmath.MaxInt32
22+
}
23+
24+
h:=0
25+
out:=0
26+
ifdividend<divisor {
27+
return0
28+
}
29+
for (divisor<<uint(h))<=dividend {
30+
h++
31+
}
32+
h--
33+
fori:=h;i>=0;i-- {
34+
ifdividend>= (divisor<<uint(i)) {
35+
dividend-= (divisor<<uint(i))
36+
out|=1<<uint(i)
37+
}
38+
}
39+
40+
if!sign {
41+
out=-out
42+
}
43+
ifout>math.MaxInt32 {
44+
returnmath.MaxInt32
45+
}elseifout<math.MinInt32 {
46+
returnmath.MinInt32
47+
}else {
48+
returnout
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
namestring
12-
inputsbool
13-
expectbool
12+
inputs[]int
13+
expectint
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:=rangecases {
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-
funcSolution(xbool)bool {
4-
returnx
3+
funcfindSubstring(sstring,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
namestring
12-
inputsbool
13-
expectbool
12+
input1string
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:=rangecases {
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)

[8]ページ先頭

©2009-2025 Movatter.jp