Skip to content

Commit fa1a01f

Browse files
committedAug 30, 2021
update some test case
1 parent 96b10a2 commit fa1a01f

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
module awesome-golang-algorithm
22

3-
go 1.15
3+
go 1.16
44

5-
require github.com/stretchr/testify v1.6.1
5+
require github.com/stretchr/testify v1.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
type SolutionFuncType func([]int) int
@@ -13,6 +14,7 @@ type SolutionFuncType func([]int) int
1314
var SolutionFuncList = []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+
func movingCount1(m int, n int, k int) int {
6+
queue := list.List{}
7+
visited := make([][]bool, m)
8+
for i := 0; i < len(visited); i++ {
9+
visited[i] = make([]bool, n)
10+
}
11+
queue.PushBack([]int{0, 0, 0, 0})
12+
res := 0
13+
for queue.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+
if i >= 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+
return res
41+
}
42+
43+
var n1, m1, k1 int
44+
var visited [][]bool
45+
46+
func movingCount2(m int, n int, k int) int {
47+
m1 = m
48+
n1 = n
49+
k1 = k
50+
visited = make([][]bool, m)
51+
for i := 0; i < len(visited); i++ {
52+
visited[i] = make([]bool, n)
53+
}
54+
55+
return dfs(0, 0, 0, 0)
56+
}
57+
58+
func dfs(i int, j int, si int, sj int) int {
59+
if i >= m1 || j >= n1 || si+sj > k1 || visited[i][j] {
60+
return 0
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+
return 1 + 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+
type SolutionFuncType func(m int, n int, k int) int
13+
14+
var SolutionFuncList = []SolutionFuncType{
15+
movingCount1,
16+
movingCount2,
17+
}
18+
19+
// test info struct
20+
type Case struct {
21+
name string
22+
input_m int
23+
input_n int
24+
input_k int
25+
expect int
26+
}
27+
28+
// test case
29+
var cases = []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+
func TestSolution(t *testing.T) {
48+
ast := assert.New(t)
49+
50+
for _, f := range SolutionFuncList {
51+
for _, c := range cases {
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)
Please sign in to comment.