Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 1.19 KB

1020-number-of-enclaves.adoc

File metadata and controls

53 lines (35 loc) · 1.19 KB

1020. Number of Enclaves

{leetcode}/problems/number-of-enclaves/[LeetCode - Number of Enclaves^]

Given a 2D array A, each cell is 0 (representing sea) or 1 (representing land)

A move consists of walking from one land square 4-directionally to another land square, or off the boundary of the grid.

Return the number of land squares in the grid for which we cannot walk off the boundary of the grid in any number of moves.

Example 1:

{image_attr}
Input: [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]]
Output: 3
Explanation:
There are three 1s that are enclosed by 0s, and one 1 that isn't enclosed because its on the boundary.

Example 2:

{image_attr}
Input: [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]]
Output: 0
Explanation:
All 1s are either on the boundary or can reach the boundary.

Note:

  1. 1 ⇐ A.length ⇐ 500

  2. 1 ⇐ A[i].length ⇐ 500

  3. 0 ⇐ A[i][j] ⇐ 1

  4. All rows have the same size.

思路分析

link:{sourcedir}/_1020_NumberOfEnclaves.java[role=include]