class Solution:
def isRobotBounded(self, instructions):
# 初始设置:[up, left, down, right]
direction = [[0, 1], [-1, 0], [0, -1], [1, 0]]
rotation = 0
x, y = 0, 0
# N - 0, W - 1, S - 2, E - 3
for i in instructions:
if i == 'L':
rotation = (rotation + 1) % 4
elif i == 'R':
rotation = (rotation + 3) % 4
else:
x += direction[rotation][0]
y += direction[rotation][1]
# 如果最终朝向不变,一定要在原点
return x == 0 and y == 0 or rotation != 0