Skip to content

Commit c117102

Browse files
author
hangyeol
committed
3번 문제풀이
1 parent ea96d21 commit c117102

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

live8/test87/문제3/백한결.py

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

0 commit comments

Comments
 (0)