Skip to content

Commit b4d33c6

Browse files
committed
87차 3번 문제 풀이
1 parent ccd7889 commit b4d33c6

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

live8/test87/문제3/박희경.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def solution(dirs):
2+
move = {
3+
"U": (0, 1),
4+
"D": (0, -1),
5+
"R": (1, 0),
6+
"L": (-1, 0)
7+
}
8+
9+
x, y = 0, 0
10+
history = set()
11+
12+
for dir in dirs:
13+
nx, ny = x + move[dir][0], y + move[dir][1]
14+
15+
if -5 <= nx <= 5 and -5 <= ny <= 5:
16+
history.add((x, y, nx, ny))
17+
history.add((nx, ny, x, y))
18+
19+
x, y = nx, ny
20+
21+
return len(history) // 2

0 commit comments

Comments
 (0)