1020. Number of Enclaves (M)
https://leetcode.com/problems/number-of-enclaves/
Last updated
https://leetcode.com/problems/number-of-enclaves/
Last updated
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
1 <= m, n <= 500
grid[i][j]
is either 0
or 1
.
Similar as LeetCode 1254
这题不让你求封闭岛屿的数量,而是求封闭岛屿的面积总和。
其实思路都是一样的,先把靠边的陆地淹掉,然后去数剩下的陆地数量就行了.