From 6484cd0dfc7b7f8bafcae12be9f7a7ed131f1d89 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sat, 22 Aug 2026 08:17:55 +0900 Subject: [PATCH] Create 1041. Robot Bounded In Circle.py --- .../1041. Robot Bounded In Circle.py" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1041. Robot Bounded In Circle.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1041. Robot Bounded In Circle.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1041. Robot Bounded In Circle.py" new file mode 100644 index 00000000..7efb8b2c --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1041. Robot Bounded In Circle.py" @@ -0,0 +1,26 @@ +class Solution: + def isRobotBounded(self, instructions: str) -> bool: + dirs = [ + [0, 1], + [1, 0], + [0, -1], + [-1, 0] + ] + + instructions *= 4 + + cords = [0, 0] + dir = 0 + + for ins in instructions: + if ins == "G": + cords[0] += dirs[dir][0] + cords[1] += dirs[dir][1] + + elif ins == "R": + dir = (dir + 1) % 4 + + elif ins == "L": + dir = (dir - 1) % 4 + + return cords == [0, 0]