728x90
나의 풀이
def solution(dirs):
direction = {'L': (-1, 0), 'U': (0, -1), 'R': (1, 0), 'D': (0, 1)}
visited = set()
x, y = 0, 0
for d in dirs:
nx, ny = x + direction[d][0], y + direction[d][1]
if -5 <= nx <= 5 and -5 <= ny <= 5:
visited.add((min(x, nx), min(y, ny), max(x, nx), max(y, ny)))
x, y = nx, ny
return len(visited)
반응형
'Coding Test > Programmers' 카테고리의 다른 글
[프로그래머스/파이썬] 가장 큰 정사각형 찾기 (0) | 2022.06.18 |
---|---|
[프로그래머스/파이썬] [3차] 방금그곡 (0) | 2022.06.18 |
[프로그래머스/파이썬] 쿼드압축 후 개수 세기 (0) | 2022.06.18 |
[프로그래머스/파이썬] n^2 배열 자르기 (0) | 2022.06.17 |
[프로그래머스/파이썬] 3 x n 타일링 (0) | 2022.06.17 |