Open yeonghwanjeon opened 5 years ago
문제
문제 풀이
def delo(numRows, numColumns, lot): queue = [(0, 0, 0)]
while len(queue) > 0: i, j, counter = queue.pop(0) if lot[i][j] == 9: return counter
if j + 1 < numColumns and lot[i][j + 1] != 0: queue.append((i, j + 1, counter + 1)) if i + 1 < numRows and lot[i + 1][j] != 0: queue.append((i + 1, j, counter + 1)) if j - 1 >= 0 and lot[i][j - 1] != 0: queue.append((i, j - 1, counter + 1)) if i - 1 >= 0 and lot[i - 1][j] != 0: queue.append((i - 1, j, counter + 1))
return -1
print(delo(3, 3, [[1, 0, 0], [1, 0, 0], [1, 9, 1]]))
문제
문제 풀이
while len(queue) > 0: i, j, counter = queue.pop(0) if lot[i][j] == 9: return counter
return -1
print(delo(3, 3, [[1, 0, 0], [1, 0, 0], [1, 9, 1]]))