Skip to content

Commit 61c7db1

Browse files
authored
🐜 Study: 방의 개수 (#86)
1 parent 7ae6f07 commit 61c7db1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

β€Žλ°©μ˜ 개수.pyβ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def solution(arrows):
2+
dx = [0, 1, 1, 1, 0, -1, -1, -1]
3+
dy = [1, 1, 0, -1, -1, -1, 0, 1]
4+
vertex, edge = {(0, 0)}, set()
5+
x, y = 0, 0
6+
for arrow in arrows:
7+
for _ in range(2):
8+
nx, ny = x + dx[arrow], y + dy[arrow]
9+
a, b = (x, y), (nx, ny)
10+
edge.add(tuple(sorted([a, b])))
11+
vertex.add((nx, ny))
12+
x, y = nx, ny
13+
return 1 - len(vertex) + len(edge)

0 commit comments

Comments
Β (0)