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

Commit58bb452

Browse files
committed
update some test case
1 parentf27b316 commit58bb452

File tree

8 files changed

+177
-6
lines changed

8 files changed

+177
-6
lines changed

‎go.mod‎

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

3-
go1.15
3+
go1.16
44

5-
requiregithub.com/stretchr/testifyv1.6.1
5+
requiregithub.com/stretchr/testifyv1.7.0

‎lcof/of000/Solution_test.go‎

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

33
import (
4-
"github.com/stretchr/testify/assert"
54
"reflect"
65
"runtime"
76
"testing"
7+
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
//solution func Info

‎lcof/of003/Solution_test.go‎

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

33
import (
4-
"github.com/stretchr/testify/assert"
54
"reflect"
65
"runtime"
76
"testing"
7+
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
typeSolutionFuncTypefunc([]int)int
@@ -13,6 +14,7 @@ type SolutionFuncType func([]int) int
1314
varSolutionFuncList= []SolutionFuncType{
1415
findRepeatNumber,
1516
findRepeatNumber2,
17+
1618
findRepeatNumber3,
1719
}
1820

‎lcof/of005/Solution_test.go‎

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

33
import (
4-
"github.com/stretchr/testify/assert"
54
"reflect"
65
"runtime"
76
"testing"
7+
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
//solution func Info

‎lcof/of006/Solution_test.go‎

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

33
import (
4-
"github.com/stretchr/testify/assert"
54
"reflect"
65
"runtime"
76
"testing"
7+
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
//solution func Info

‎lcof/of013/README.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#[OF0.Template Title][title]
2+
3+
>[!WARNING|style:flat]
4+
>This problem is temporarily not PR, please submit[Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5+
6+
7+
##题目描述
8+
....
9+
10+
**范例 :**
11+
12+
```
13+
Input: n=1
14+
Output: 1
15+
```
16+
17+
##题意
18+
>...
19+
20+
##题解
21+
22+
###思路1
23+
>...
24+
```go
25+
```
26+
27+
##结语
28+
29+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-algorithm][me]
30+
31+
[title]:https://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3/
32+
[me]:https://github.com/kylesliu/awesome-golang-algorithm

‎lcof/of013/Solution.go‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package Solution
2+
3+
import"container/list"
4+
5+
funcmovingCount1(mint,nint,kint)int {
6+
queue:= list.List{}
7+
visited:=make([][]bool,m)
8+
fori:=0;i<len(visited);i++ {
9+
visited[i]=make([]bool,n)
10+
}
11+
queue.PushBack([]int{0,0,0,0})
12+
res:=0
13+
forqueue.Len()>0 {
14+
back:=queue.Back()
15+
queue.Remove(back)
16+
bfs:=back.Value.([]int)
17+
i:=bfs[0]
18+
j:=bfs[1]
19+
si:=bfs[2]
20+
sj:=bfs[3]
21+
ifi>=m||j>=n||si+sj>k||visited[i][j] {
22+
continue
23+
}
24+
25+
res++
26+
visited[i][j]=true
27+
28+
sj1:=sj+1
29+
si1:=si+1
30+
if (j+1)%10==0 {
31+
sj1=sj-8
32+
}
33+
if (i+1)%10==0 {
34+
si1=si-8
35+
}
36+
37+
queue.PushBack([]int{i+1,j,si1,sj})
38+
queue.PushBack([]int{i,j+1,si,sj1})
39+
}
40+
returnres
41+
}
42+
43+
varn1,m1,k1int
44+
varvisited [][]bool
45+
46+
funcmovingCount2(mint,nint,kint)int {
47+
m1=m
48+
n1=n
49+
k1=k
50+
visited=make([][]bool,m)
51+
fori:=0;i<len(visited);i++ {
52+
visited[i]=make([]bool,n)
53+
}
54+
55+
returndfs(0,0,0,0)
56+
}
57+
58+
funcdfs(iint,jint,siint,sjint)int {
59+
ifi>=m1||j>=n1||si+sj>k1||visited[i][j] {
60+
return0
61+
}
62+
visited[i][j]=true
63+
64+
sj1:=sj+1
65+
si1:=si+1
66+
if (j+1)%10==0 {
67+
sj1=sj-8
68+
}
69+
if (i+1)%10==0 {
70+
si1=si-8
71+
}
72+
73+
return1+dfs(i,j+1,si,sj1)+dfs(i+1,j,si1,sj)
74+
}

‎lcof/of013/Solution_test.go‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package Solution
2+
3+
import (
4+
"reflect"
5+
"runtime"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
//solution func Info
12+
typeSolutionFuncTypefunc(mint,nint,kint)int
13+
14+
varSolutionFuncList= []SolutionFuncType{
15+
movingCount1,
16+
movingCount2,
17+
}
18+
19+
//test info struct
20+
typeCasestruct {
21+
namestring
22+
input_mint
23+
input_nint
24+
input_kint
25+
expectint
26+
}
27+
28+
// test case
29+
varcases= []Case{
30+
{
31+
name:"TestCase 1",
32+
input_m:2,
33+
input_n:3,
34+
input_k:1,
35+
expect:3,
36+
},
37+
{
38+
name:"TestCase 2",
39+
input_m:3,
40+
input_n:1,
41+
input_k:0,
42+
expect:1,
43+
},
44+
}
45+
46+
// TestSolution Example for solution test cases
47+
funcTestSolution(t*testing.T) {
48+
ast:=assert.New(t)
49+
50+
for_,f:=rangeSolutionFuncList {
51+
for_,c:=rangecases {
52+
t.Run(c.name,func(t*testing.T) {
53+
actual:=f(c.input_m,c.input_n,c.input_k)
54+
ast.Equal(c.expect,actual,
55+
"func: %v case: %v ",
56+
runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(),c.name)
57+
})
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp