레벨2 문제 실패
from collections import deque
def solution(maps):
ds = [-1, 1, 0, 0]
dg = [0, 0, -1, 1]
def bfs(s, g):
queue = deque()
queue.append((s, g))
while queue:
s, g = queue.popleft()
for i in range(4):
move_s = s + ds[i]
move_g = g + dg[i]
if ( move_s < 0 or move_s >= len(maps) or move_g < 0 or move_g >= len(maps[0]) ):
continue
if maps[move_s][move_g] == 0:
continue
if maps[move_s][move_g] == 1:
maps[move_s][move_g] = maps[s][g] + 1
queue.append((move_s, move_g))
if ( maps[-1][-1] == 0 or maps[-1][-1] == 1 ):
return -1
return maps[-1][-1]
answer = bfs(0, 0)
return answer