Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 752e80b

Browse files
aQuaaQua
aQua
authored and
aQua
committed
789 finish
1 parent 7e289f2 commit 752e80b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Algorithms/0789.escape-the-ghosts/escape-the-ghosts.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ func escapeGhosts(ghosts [][]int, target []int) bool {
44
steps := countSteps([]int{0, 0}, target)
55
for _, g := range ghosts {
66
if steps >= countSteps(g, target) {
7+
// 表示 ghost 可以在终点等着
78
return false
89
}
910
}
@@ -15,8 +16,8 @@ func countSteps(from, to []int) int {
1516
}
1617

1718
func abs(n int) int {
18-
if n > 0 {
19-
return n
19+
if n < 0 {
20+
return -n
2021
}
21-
return -n
22+
return n
2223
}

Algorithms/0789.escape-the-ghosts/escape-the-ghosts_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var tcs = []struct {
1515
}{
1616

1717
{
18-
[][]int { { -1,0 },{ 0,1 },{ -1,0 },{ 0,1 },{ -1,0 } },
19-
[]int{ 0,0 },
18+
[][]int{{-1, 0}, {0, 1}, {-1, 0}, {0, 1}, {-1, 0}},
19+
[]int{0, 0},
2020
true,
2121
},
2222

0 commit comments

Comments
 (0)