Algorithm
Walking Robot Simulation II
Solution
class Robot:
TO_DIR = { 0: "East", 1: "North", 2: "West", 3: "South" }
def __init__(self, width: int, height: int):
self.moved = False
self.idx = 0
self.pos = list()
self.dirs = list()
pos_, dirs_ = self.pos, self.dirs
for i in range(width):
pos_.append((i, 0))
dirs_.append(0)
for i in range(1, height):
pos_.append((width - 1, i))
dirs_.append(1)
for i in range(width - 2, -1, -1):
pos_.append((i, height - 1))
dirs_.append(2)
for i in range(height - 2, 0, -1):
pos_.append((0, i))
dirs_.append(3)
dirs_[0] = 3Video GuideLeetcode Daily
Time Complexity
O(width + height)
Space Complexity
O(width + height)
