Medium
,Array
,DFS
,BFS
,Matrix
You are given an m x n
binary matrix grid
, where 0
represents a sea cell and 1
represents a land cell.
A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid
.
Return the number of land cells in grid
for which we cannot walk off the boundary of the grid in any number of moves.
Example 1:
Example 2:
Constraints:
m
== grid.length
n
== grid[i].length
m
, n
<= 500grid[i][j]
is either 0
or 1
.跟昨天那題解法 87% 像
Ron Chen Fri, Apr 7, 2023
從四個邊下去dfs,走過的地方都修改為0,最後回傳加總得到仍為1的數量。
Yen-Chi ChenFri, Apr 7, 2023
寫得非常之笨
MarsgoatApr 8, 2023