1
# Runtime: 970 ms (Top 9.86%) | Memory: 20.6 MB (Top 59.47%)
2
class Solution:
3
def robotSim(self, commands: List[int], obstacles: List[List[int]]) -> int:
4
obs = set(tuple(o) for o in obstacles)
5
x = y = a = out = 0
6
move = {0: (0, 1), 90: (1, 0), 180: (0, -1), 270: (-1, 0)}
7
for c in commands:
8
if c == -1:
9
a += 90
10
elif c == -2:
11
a -= 90
12
else:
13
direction = a % 360
14
dx, dy = move[direction]
15
for _ in range(c):
16
if (x + dx, y + dy) in obs:
17
break
18
x += dx
19
y += dy
20
out = max(out, x**2 + y**2)
21
return out

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0