Search
Duplicate

방문 길이

Level
2
문제 진행 상태
코드 완료
해설 작성 중
알고리즘 & 자료구조
리스트
해시
정답률 (%)
59
태그
연습문제

문제 링크

풀이 과정

전체 코드

def isin_boundary(cy, cx): ''' y: 세로 방향의 좌표 x: 가로 방향의 좌표 ''' return -5 <= cy <= 5 and -5 <= cx <= 5 def solution(dirs): answer = 0 directions = {'U': (-1, 0), 'L': (0, -1), 'R': (0, 1), 'D': (1, 0)} traces = set() cx, cy = 0, 0 for direction in dirs: dy, dx = directions[direction] ny, nx = cy + dy, cx + dx if isin_boundary(ny, nx): if (cy, cx, ny, nx) not in traces: traces.add((cy, cx, ny, nx)) traces.add((ny, nx, cy, cx)) cy, cx = ny, nx return len(traces) / 2
Python
복사