From ac8479d6801025a1fb8b51db7012b37988a5593c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Sat, 22 Aug 2026 23:48:12 +0900 Subject: [PATCH] Create 1041. Robot Bounded In Circle.java --- .../1041. Robot Bounded In Circle.java" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/1041. Robot Bounded In Circle.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/1041. Robot Bounded In Circle.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/1041. Robot Bounded In Circle.java" new file mode 100644 index 00000000..7a3c338d --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/1041. Robot Bounded In Circle.java" @@ -0,0 +1,17 @@ +class Solution { + public boolean isRobotBounded(String instructions) { + int x = 0, y = 0, dir = 0; + int[][] moves = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; + for (char c : instructions.toCharArray()) { + if (c == 'G') { + x += moves[dir][0]; + y += moves[dir][1]; + } else if (c == 'L') { + dir = (dir + 3) % 4; + } else { + dir = (dir + 1) % 4; + } + } + return (x == 0 && y == 0) || dir != 0; + } +}