Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions leetcode3/변지협/v2/1041. Robot Bounded In Circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
right_dict = {(0,1):(1,0),(1,0):(0,-1),(0,-1):(-1,0),(-1,0):(0,1)}
left_dict = {(0,1):(-1,0),(-1,0):(0,-1),(0,-1):(1,0),(1,0):(0,1)}

class Solution:
x = 0
y = 0
direction = (0,1)

def play(self, instructions):
for i in instructions:
if i == 'G':
x_dir, y_dir = self.direction
self.x += x_dir
self.y += y_dir
elif i == 'L':
self.direction = left_dict[self.direction]
else:
self.direction = right_dict[self.direction]

def isRobotBounded(self, instructions: str) -> bool:
self.play(instructions)
for _ in range(4):
self.play(instructions)
if self.x ==0 and self.y == 0:
return True

return False