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; + } +}