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

Commit 1531de6

Browse files
committed
1041 accepted.
1 parent 235c028 commit 1531de6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Algorithms/1041.robot-bounded-in-circle/robot-bounded-in-circle.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package problem1041
22

33
func isRobotBounded(instructions string) bool {
4+
print(north, east, south, west)
45
r := newRobot()
56
for _, i := range instructions {
67
r.receive(i)
78
}
8-
return (r.x == 0 && r.y == 0) ||
9-
(r.d != north)
9+
return (r.x == 0 && r.y == 0) || // 每轮都会回到原点,就永远会回到原点
10+
(r.d != north) // 第一轮后,没有回到原点,但是方向改变,至多 4 轮后,还是会回到原点
1011
}
1112

1213
type direction int
@@ -56,5 +57,5 @@ func (r *robot) turn(instruction rune) {
5657
} else {
5758
r.d--
5859
}
59-
r.d = r.d % 4
60+
r.d = (r.d + 4) % 4
6061
}

0 commit comments

Comments
 (0)