1
# Runtime: 34 ms (Top 89.04%) | Memory: 14 MB (Top 22.71%)
2

3

4
class Solution:
5
def isRobotBounded(self, instructions: str) -> bool:
6
pos, d = [0, 0], "N"
7

8
def move(d, pos, instructions):
9
for i in instructions:
10
if i == "G":
11
if d == "N":
12
pos[1] += 1
13
elif d == "S":
14
pos[1] -= 1
15
elif d == "W":
16
pos[0] -= 1
17
else:
18
pos[0] += 1
19
elif i == "L":
20
if d == "N":
21
d = "W"
22
elif d == "W":
23
d = "S"
24
elif d == "S":
25
d = "E"
26
else:
27
d = "N"
28
else:
29
if d == "N":
30
d = "E"
31
elif d == "W":
32
d = "N"
33
elif d == "S":
34
d = "W"
35
else:
36
d = "S"
37
return (d, pos)
38

39
for i in range(4):
40
d, pos = move(d, pos, instructions)
41
return True if pos == [0, 0] else False

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0