def solution(dirs):
an = {}
U = 0 ; D = 0 ;R = 0 ; L = 0
location = [0,0]
for i in dirs:
road = str(location)
if i == 'L':
if location[0] == -5:
pass
else:
location[0] -= 1
a = str(location)
road1 = a+road
road += a
if (road not in an) and (road1 not in an):
an[road]=0
elif i == 'R':
if location[0] == 5:
pass
else:
location[0] += 1
a = str(location)
road1 = a+road
road += a
if (road not in an) and (road1 not in an):
an[road]=0
elif i == 'U':
if location[1] == 5:
pass
else:
location[1] += 1
a = str(location)
road1 = a+road
road += a
if (road not in an) and (road1 not in an):
an[road]=0
elif i == 'D':
if location[1] == -5:
pass
else:
location[1] -= 1
a = str(location)
road1 = a+road
road += a
if (road not in an) and (road1 not in an):
an[road]=0
answer = len(an)
return answer
풀이
이 반례만 해결하면 되는 문제다.
"LLLLLLUURRRDDLURL" / 14
한 번 왔던 길은 다시 가게 된다해도 포함시키면 안된다.
즉 '[0,1] -> [0,2]' 이렇게 이동한다고 할 때 '[0,2] -> [0,1]'이 만약 딕셔너리에 포함되어있으면 이 경로는 제외해야한다는 뜻이다!