五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 1020 Number of Enclaves

2023-03-07 08:11 作者:您是打尖兒還是住店呢  | 我要投稿

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:

Input: grid = [[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 is not enclosed because its on the boundary.

Example 2:

Input: grid = [[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.

?

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1 <= m, n <= 500

  • grid[i][j]?is either?0?or?1.

Accepted

95,195

Submissions

145,440

DFS 一定要有返回的條件,不然直接就內(nèi)存溢出了。。。

相當(dāng)于把邊上為1的數(shù)字直接改成0,當(dāng)然包含跟他相鄰的數(shù)字,

然后再計算剩下1的數(shù)量,返回即可。


Runtime:?9 ms, faster than?76.21%?of?Java?online submissions for?Number of Enclaves.

Memory Usage:?53.8 MB, less than?76.65%?of?Java?online submissions for?Number of Enclaves.


LeetCode 1020 Number of Enclaves的評論 (共 條)

分享到微博請遵守國家法律
洪洞县| 安西县| 高唐县| 郁南县| 吴桥县| 阿拉善盟| 鄄城县| 青神县| 和硕县| 中牟县| 那坡县| 旺苍县| 昆明市| 琼海市| 合川市| 江口县| 阆中市| 炎陵县| 夏邑县| 平邑县| 南靖县| 宝应县| 鸡东县| 青冈县| 平顺县| 渭源县| 大新县| 准格尔旗| 佛教| 荔波县| 临清市| 中卫市| 衡东县| 扎鲁特旗| 汕头市| 海城市| 贵德县| 宝丰县| 昌江| 安阳县| 安庆市|