Medium
,Array
,BFS
,Matrix
1091. Shortest Path in Binary Matrix
Given an n x n
binary matrix grid
, return the length of the shortest clear path in the matrix. If there is no clear path, return -1
.
A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-right cell (i.e., (n - 1, n - 1)) such that:
0
.The length of a clear path is the number of visited cells of this path.
Example 1:
Example 2:
Example 3:
Constraints:
n
== grid.length
n
== grid[i].length
n
<= 100grid[i][j]
is 0
or 1
BFS
Jerry Wu1 June, 2023
跟1926超像,好幾題類似題,但我還是因為邊界問題錯了兩次…
Marsgoat1 June, 2023