Skip to content

Commit be8371d

Browse files
committed
87차 3번 문제풀이
1 parent 81695e7 commit be8371d

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

live8/test87/문제3/백유진.py

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

0 commit comments

Comments
 (0)