From 5aa60f4146393fd9b8ad3d581e0c6f07cf9b5a33 Mon Sep 17 00:00:00 2001 From: rimgosu Date: Sat, 22 Aug 2026 19:22:40 +0900 Subject: [PATCH] 1041 --- .../v2/1041. Robot Bounded In Circle.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v2/1041. Robot Bounded In Circle.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1041. Robot Bounded In Circle.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1041. Robot Bounded In Circle.py" new file mode 100644 index 00000000..4ab21fc6 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1041. Robot Bounded In Circle.py" @@ -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 + \ No newline at end of file