dictionary와 set을 적절히 활용하는 문제였다
이미 지나간 길은 무시하기 위해서 add를 두번 해주어야 했다
소스 코드
def solution(dirs):
d = {'U':(0, -1), 'D':(0, 1), 'L':(-1,0), 'R':(1,0)}
move = set()
cur_x, cur_y = (0, 0)
for i in dirs:
next_x, next_y = cur_x + d[i][0], cur_y + d[i][1]
if -5 <= next_x <= 5 and -5 <= next_y <= 5:
move.add((cur_x, cur_y, next_x, next_y))
move.add((next_x, next_y, cur_x, cur_y))
cur_x, cur_y = next_x, next_y
return len(move) // 2