def solution(arrows):
direction = [
[0,1],
[1,1],
[1,0],
[1,-1],
[0,-1],
[-1,-1],
[-1,0],
[-1,1],
]
answer = 0
dic = {}
path = {}
x, y = 0, 0
dic[str([x, y])] = True
for item in arrows:
for i in range(2) :
nextx, nexty = x + direction[item][0], y + direction[item][1]
pathKey = str([x, y, nextx, nexty])
pathKey2 = str([nextx, nexty, x, y])
dicKey = str([nextx, nexty])
if not dicKey in dic :
path[pathKey] = True
path[pathKey2] = True
dic[dicKey] = True
else :
if not pathKey in path :
path[pathKey] = True
path[pathKey2] = True
answer += 1
x, y = nextx, nexty
return answer
딕셔너리의 키 값을 입력할때
dicKey = f'{nextx}{nexty}' 는 테스트 케이스는 되는데 제출만 하면 40점도 안나왔다. 아무리봐도 로직에는 문제가 없어서 dicKey = str([nextx, nexty]) 이렇게 바꿔봤더니 잘 동작한다.... 후 힘들었다
'컴퓨터 > 코테' 카테고리의 다른 글
프로그래머스 징검다리 건너기 (0) | 2021.08.12 |
---|---|
프로그래머스 - 디스크 컨트롤러[heap] (0) | 2021.08.12 |
릿코드 3 - Longest Substring, 카카오 보석쇼핑 (0) | 2021.08.11 |
릿코드 84 - Largest Rectangle in Histogram (0) | 2021.08.10 |
릿코드 338 - 2진법 변환 (0) | 2021.08.10 |