机器人在一个无限大小的 XY 网格平面上行走,从点 (0, 0) 处开始出发,面向北方。该机器人可以接收以下三种类型的命令 commands :
-2 :向左转 90 度
-1 :向右转 90 度
1 <= x <= 9 :向前移动 x 个单位长度
在网格上有一些格子被视为障碍物 obstacles 。第 i 个障碍物位于网格点 obstacles[i] = (xi, yi) 。
机器人无法走到障碍物上,它将会停留在障碍物的前一个网格方块上,并继续执行下一个命令。
返回机器人距离原点的 最大欧式距离的平方 。(即,如果距离为 5 ,则返回 25 )
class Solution:
def __init__(self):
"""initialization"""
self.d = 0 # direction sign
self.rot = [-1, -2] # rotation
self.org = [0, 0] # origin
self.dir = [[0, 1], [1, 0], [0, -1], [-1, 0]] # direction
def robotSim(self, commands, obstacles):
x, y = self.org
max_distance = 0
obstacle_set = set(map(tuple, obstacles))
for command in commands:
if command in self.rot:
if command