class Solution:
def robot(self, command: str, obstacles: List[List[int]], x: int, y: int) -> bool:
u,r=0,0
for m in command:
if m=="U":
u+=1
else:
r+=1
def reach(x,y):
rnd = min(x//r, y//u)
nx, ny = r*rnd, u*rnd
for m in command:
# 判断语句写在这里即可
# 如果能到达(x,y),无需判断command最后一步
# 假如最后一步能到达(x,y), 那 (nx,ny) 就是(x,y)
if nx == x and ny == y:
return True
if m == "U":
ny+=1
else:
nx+=1
return False
for ob in obstacles:
if ob[0] <= x and ob[1] <= y and reach(*ob):
return False
return reach(x,y)