Skip to content

Commit 42e13c8

Browse files
committed
게임 맵 최단거리 문제 추가
1 parent 557aeeb commit 42e13c8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections import deque
2+
3+
def solution(maps):
4+
dir = [(1,0),(0,1),(-1,0),(0,-1)]
5+
6+
n = len(maps)
7+
m = len(maps[0])
8+
9+
queue = deque()
10+
queue.append((0,0))
11+
12+
while queue:
13+
row,colum = queue.popleft()
14+
for x,y in dir:
15+
if row+x >= 0 and row+x < n and colum + y >= 0 and colum +y < m:
16+
if maps[row+x][colum+y] == 1:
17+
queue.append((row+x, colum+y))
18+
maps[row+x][colum+y] = maps[row][colum] + 1
19+
20+
if maps[n-1][m-1] == 1:
21+
answer = -1
22+
else:
23+
answer = maps[n-1][m-1]
24+
25+
return answer

0 commit comments

Comments
 (0)