当前位置:网站首页>[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 .
边栏推荐
- 嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利
- Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
- GPS从入门到放弃(十五)、DCB差分码偏差
- HDR image reconstruction from a single exposure using deep CNNs阅读札记
- 11、 Service introduction and port
- GPS from entry to abandonment (XIV), ionospheric delay
- MongoDB(三)——CRUD
- Search element topic (DFS)
- Run the deep network on PI and Jetson nano, and the program is killed
- AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
猜你喜欢

Embedded common computing artifact excel, welcome to recommend skills to keep the document constantly updated and provide convenience for others

Management background --2 Classification list
![[MySQL] online DDL details](/img/7e/97098d7ed5802c446bbadaf7035981.png)
[MySQL] online DDL details

UNI-Admin基础框架怎么关闭创建超级管理员入口?

Write a rotation verification code annotation gadget with aardio

2500个常用中文字符 + 130常用中英文字符

Checkpoint of RDD in spark

Vit paper details

About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness

Management background --3, modify classification
随机推荐
Common sense: what is "preservation" in insurance?
The underlying implementation of string
Kohana database
2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
Four data streams of grpc
Set status bar style demo
CCNA-思科网络 EIGRP协议
3DMax指定面贴图
Unity3D学习笔记6——GPU实例化(1)
十二、启动流程
Yyds dry goods inventory C language recursive implementation of Hanoi Tower
【sciter Bug篇】多行隐藏
20 large visual screens that are highly praised by the boss, with source code templates!
Save and retrieve strings
Some problems about the use of char[] array assignment through scanf..
zabbix 代理服务器 与 zabbix-snmp 监控
[Yu Yue education] reference materials for surgical skills teaching in Tongji University
LeetCode:1189. The maximum number of "balloons" -- simple
QT | UDP broadcast communication, simple use case
anaconda安装第三方包