1 parent 8db7f2e commit ecd671dCopy full SHA for ecd671d
1 file changed
leetcode3/최민지/1041-robot-bounded-in-circle.py
@@ -0,0 +1,28 @@
1
+class Solution:
2
+ def isRobotBounded(self, instructions: str) -> bool:
3
+ x, y = 0, 0
4
+
5
+ # 북, 동, 남, 서
6
+ directions = [
7
+ (0, 1),
8
+ (1, 0),
9
+ (0, -1),
10
+ (-1, 0)
11
+ ]
12
13
+ direction = 0
14
15
+ for instruction in instructions:
16
+ if instruction == 'G':
17
+ dx, dy = directions[direction]
18
+ x += dx
19
+ y += dy
20
21
+ elif instruction == 'R':
22
+ direction = (direction + 1) % 4
23
24
+ elif instruction == 'L':
25
+ direction = (direction - 1) % 4
26
27
+ return (x == 0 and y == 0) or direction != 0
28
0 commit comments