874. Walking Robot Simulation
## 思路
先把obstacles改为set 方便检查
然后模拟
记录command移动后的最大距离平方和
## Code
```python
class Solution:
def robotSim(self, commands: List[int], obstacles: List[List[int]]) ->
int:
obstacles = {(x, y) for x, y in obstacles}
res = 0
x = y = i = 0
dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)]
for cmd in commands:
if cmd == -1:
i = (i+1) % 4
elif cmd == -2:
i = (i-1) % 4
else:
for _ in range(cmd):
nx, ny = x + dirs[i][0], y + dirs[i][1]
if (nx, ny) in obstacles:
break
x, y = nx, ny
res = max(res, x * x + y * y)
return res
```