Skip to content

Commit 6484cd0

Browse files
authored
Create 1041. Robot Bounded In Circle.py
1 parent 8b28dde commit 6484cd0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def isRobotBounded(self, instructions: str) -> bool:
3+
dirs = [
4+
[0, 1],
5+
[1, 0],
6+
[0, -1],
7+
[-1, 0]
8+
]
9+
10+
instructions *= 4
11+
12+
cords = [0, 0]
13+
dir = 0
14+
15+
for ins in instructions:
16+
if ins == "G":
17+
cords[0] += dirs[dir][0]
18+
cords[1] += dirs[dir][1]
19+
20+
elif ins == "R":
21+
dir = (dir + 1) % 4
22+
23+
elif ins == "L":
24+
dir = (dir - 1) % 4
25+
26+
return cords == [0, 0]

0 commit comments

Comments
 (0)