스터디/코딩테스트 연습
방문 길이
YONS
2022. 1. 27. 14:22
def solution(dirs):
px, py = 0, 0
finished = []
for i in dirs:
imsimove = [(px, py)]
if i == 'U' and px < 5:
px += 1
elif i == 'D' and px > -5:
px -= 1
elif i == 'R' and py < 5:
py += 1
elif i == 'L' and py > -5:
py -= 1
else:
continue
imsimove.append((px, py))
if finished.count([imsimove[1],imsimove[0]]) == 0 and finished.count(imsimove) == 0:
finished.append(imsimove)
answer = len(finished)
return answer