Robot
489. Robot Room Cleaner
class Robot:
def move(self)"
"""
Returns true and robot moves into the cell.
Returns false if the cell in front is blocked.
"""
def turnLeft(self)
def turnRight(self)
def clean(self)def cleanRoom(self, robot):
"""
:type robot: Robot
:rtype: None
"""
dirs = ((0, 1), (1, 0), (0, -1), (-1, 0))
visit = set()
def goBack():
robot.turnRight()
robot.turnRight()
robot.move()
robot.turnRight()
robot.turnRight()
def backtrack(x = 0, y = 0, d = 0):
visit.add((x, y))
robot.clean()
for i in range(4):
newD = (d + i) % 4
newX = x + dirs[newD][0]
newY = y + dirs[newD][1]
if (newX, newY) not in visit and robot.move():
backtrack(newX, newY, newD)
goBack()
robot.turnRight()
backtrack()657. Robot Return to Origin
874. Walking Robot Simulation
1041. Robot Bounded In Circle
Last updated