Skip to content

Commit 3c95876

Browse files
committed
[level 2] Title: 방문 길이, Time: 0.36 ms, Memory: 9.2 MB -BaekjoonHub
1 parent 0570ba3 commit 3c95876

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

프로그래머스/2/49994. 방문 길이/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 10.2 MB, 시간: 0.36 ms
7+
메모리: 9.2 MB, 시간: 0.36 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2024년 10월 17일 11:11:24
19+
2026년 01월 05일 15:09:21
2020

2121
### 문제 설명
2222

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
def solution(dirs):
2-
sets = set()
3-
udirl = {"U": (0, 1), "D": (0, -1), "R": (1, 0), "L": (-1, 0)}
2+
move = {"U": (0, 1), "D": (0, -1), "L": (-1, 0), "R": (1, 0)}
3+
44
x, y = 0, 0
5+
record = set()
56

67
for d in dirs:
7-
dx, dy = udirl[d]
8-
ny = y + dy
9-
nx = x + dx
8+
dx, dy = move[d]
9+
nx, ny = x + dx, y + dy
1010

1111
if -5 <= nx <= 5 and -5 <= ny <= 5:
12-
sets.add(((x, y), (nx, ny)))
13-
sets.add(((nx, ny), (x, y)))
14-
y = ny
15-
x = nx
16-
return len(sets) // 2
12+
path = tuple(sorted([(x, y), (nx, ny)]))
13+
record.add(path)
14+
15+
x, y = nx, ny
16+
17+
return len(record)

0 commit comments

Comments
 (0)