diff --git "a/leetcode3/\354\265\234\353\257\274\354\247\200/1041-robot-bounded-in-circle.py" "b/leetcode3/\354\265\234\353\257\274\354\247\200/1041-robot-bounded-in-circle.py" new file mode 100644 index 00000000..35ef5be9 --- /dev/null +++ "b/leetcode3/\354\265\234\353\257\274\354\247\200/1041-robot-bounded-in-circle.py" @@ -0,0 +1,28 @@ +class Solution: + def isRobotBounded(self, instructions: str) -> bool: + x, y = 0, 0 + + # 뢁, 동, 남, μ„œ + directions = [ + (0, 1), + (1, 0), + (0, -1), + (-1, 0) + ] + + direction = 0 + + for instruction in instructions: + if instruction == 'G': + dx, dy = directions[direction] + x += dx + y += dy + + elif instruction == 'R': + direction = (direction + 1) % 4 + + elif instruction == 'L': + direction = (direction - 1) % 4 + + return (x == 0 and y == 0) or direction != 0 + \ No newline at end of file