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

Commiteb879d1

Browse files
author
Kyle Liu
authored
Merge pull request6boris#154 from kylesliu/develop
add 203 solution
2 parentsdc80402 +27df565 commiteb879d1

File tree

2 files changed

+41
-12
lines changed

2 files changed

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

3-
funcSolution(xbool)bool {
4-
returnx
3+
typeListNodestruct {
4+
Valint
5+
Next*ListNode
6+
}
7+
8+
funcremoveElements(head*ListNode,valint)*ListNode {
9+
tmp:=&ListNode{}
10+
11+
tmp.Next=head
12+
13+
forp:=tmp;p!=nil; {
14+
ifp.Next!=nil&&p.Next.Val==val {
15+
p.Next=p.Next.Next
16+
17+
}else {
18+
p=p.Next
19+
}
20+
}
21+
returntmp.Next
522
}

‎src/0203.Remove-Linked-List-Elements/Solution_test.go

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

33
import (
4-
"reflect"
4+
"fmt"
55
"strconv"
66
"testing"
77
)
@@ -10,22 +10,34 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
14-
expectbool
13+
inputs*ListNode
14+
valint
15+
expect*ListNode
1516
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
17+
{"TestCase",&ListNode{
18+
Val:1,Next:&ListNode{
19+
Val:2,Next:&ListNode{
20+
Val:6,Next:&ListNode{
21+
Val:3,Next:&ListNode{
22+
Val:4,Next:&ListNode{
23+
Val:5,Next:&ListNode{
24+
Val:6,Next:nil,
25+
},
26+
},
27+
},
28+
},
29+
}}},6,&ListNode{}},
1930
}
2031

2132
//开始测试
2233
fori,c:=rangecases {
2334
t.Run(c.name+" "+strconv.Itoa(i),func(t*testing.T) {
24-
got:=Solution(c.inputs)
25-
if!reflect.DeepEqual(got,c.expect) {
26-
t.Fatalf("expected: %v, butgot: %v, with inputs: %v",
27-
c.expect,got,c.inputs)
35+
got:=removeElements(c.inputs,c.val)
36+
forgot!=nil {
37+
fmt.Print(got.Val," ")
38+
got=got.Next
2839
}
40+
2941
})
3042
}
3143
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp