Skip to content

Commit dfe720a

Browse files
Merge pull request #1886 from CodingTestStudy2/최민지
[최민지] Day24
2 parents 3e4644e + ecd671d commit dfe720a

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)