当前位置:网站首页>[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 .
边栏推荐
- MariaDB database management system learning (I) installation diagram
- Unity3d Learning Notes 6 - GPU instantiation (1)
- Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
- Aggregate function with key in spark
- Checkpoint of RDD in spark
- Unity3D学习笔记6——GPU实例化(1)
- 2500个常用中文字符 + 130常用中英文字符
- 小常识:保险中的“保全”是什么?
- Four data streams of grpc
- Uni app app half screen continuous code scanning
猜你喜欢

Persistence / caching of RDD in spark

【MySQL】Online DDL详解

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

3DMax指定面贴图

GPS从入门到放弃(十二)、 多普勒定速

GPS从入门到放弃(十四)、电离层延时

Adjustable DC power supply based on LM317

ZABBIX proxy server and ZABBIX SNMP monitoring

GPS from getting started to giving up (XV), DCB differential code deviation

2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
随机推荐
Reinforcement learning - learning notes 5 | alphago
[10:00 public class]: basis and practice of video quality evaluation
GPS从入门到放弃(十四)、电离层延时
GPS从入门到放弃(十七) 、对流层延时
OpenCV300 CMake生成project在项目过程中的问题
GPS从入门到放弃(十九)、精密星历(sp3格式)
What is the RDD operator in spark
MariaDb数据库管理系统的学习(一)安装示意图
A Mexican airliner bound for the United States was struck by lightning after taking off and then returned safely
美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断
Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
Kohana database
GPS from getting started to giving up (XI), differential GPS
Set status bar style demo
Management background --1 Create classification
20 large visual screens that are highly praised by the boss, with source code templates!
Oracle-控制文件及日志文件的管理
Vit paper details
Classic sql50 questions
Mongodb (III) - CRUD