当前位置:网站首页>[leetcode daily clock in] 1020 Number of enclaves
[leetcode daily clock in] 1020 Number of enclaves
2022-07-06 22:11:00 【yyhnet. cn】
![[]](/img/2d/3d12f20c8c73fb28044c01be633c99.jpg)
class Solution:
def numEnclaves(self, grid: List[List[int]]) -> int:
m, n = len(grid), len(grid[0])
vis = [[False] * n for _ in range(m)]
def dfs(r: int, c: int) -> None:
if r < 0 or r >= m or c < 0 or c >= n or grid[r][c] == 0 or vis[r][c]:
return
vis[r][c] = True
for x, y in ((r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)):
dfs(x, y)
for i in range(m):
dfs(i, 0)
dfs(i, n - 1)
for j in range(1, n - 1):
dfs(0, j)
dfs(m - 1, j)
return sum(grid[i][j] and not vis[i][j] for i in range(1, m - 1) for j in range(1, n - 1))
1. adopt DFS Traversal can calculate whether the current point can go to the ground , If the current point is not outside the boundary and is land , And it is marked as True, And continue to traverse the surrounding points .
2. By judging the number of ground that cannot be walked out , That is, the current statistics is False Land parcel of , You can get the answer .
边栏推荐
- Intelligent online customer service system source code Gofly development log - 2 Develop command line applications
- GPS from entry to abandonment (XVII), tropospheric delay
- GPS du début à l'abandon (XIII), surveillance autonome de l'intégrité du récepteur (raim)
- [MySQL] online DDL details
- QT | UDP broadcast communication, simple use case
- Huawei has launched attacks in many industries at the same time, and its frightening technology has made European and American enterprises tremble
- GPS从入门到放弃(十九)、精密星历(sp3格式)
- 十二、启动流程
- Earned value management EVM detailed explanation and application, example explanation
- MongoDB(三)——CRUD
猜你喜欢

3DMax指定面贴图

【sciter】: 基于 sciter 封装通知栏组件

C#實現水晶報錶綁定數據並實現打印4-條形碼
![[Chongqing Guangdong education] Tianjin urban construction university concrete structure design principle a reference](/img/61/976c7d86ab3b2df5f5af3beefbf547.png)
[Chongqing Guangdong education] Tianjin urban construction university concrete structure design principle a reference

GPS从入门到放弃(十七) 、对流层延时

GPS from entry to abandonment (XIV), ionospheric delay

GPS从入门到放弃(十九)、精密星历(sp3格式)

Checkpoint of RDD in spark

GPS from entry to abandonment (XVII), tropospheric delay

A Mexican airliner bound for the United States was struck by lightning after taking off and then returned safely
随机推荐
How does the uni admin basic framework close the creation of super administrator entries?
Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1
MariaDb数据库管理系统的学习(一)安装示意图
插入排序与希尔排序
2500 common Chinese characters + 130 common Chinese and English characters
Method return value considerations
CCNA-思科网络 EIGRP协议
Is it important to build the SEO foundation of the new website
GPS from getting started to giving up (12), Doppler constant speed
Support multiple API versions in flask
Save and retrieve strings
Common sense: what is "preservation" in insurance?
Make menuconfig has a recipe for target 'menuconfig' failed error
Some problems about the use of char[] array assignment through scanf..
Barcodex (ActiveX print control) v5.3.0.80 free version
GPS从入门到放弃(二十)、天线偏移
Uni app app half screen continuous code scanning
Vit paper details
解决项目跨域问题
GNN,请你的网络层数再深一点~