当前位置:网站首页>[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 .
边栏推荐
- Is it important to build the SEO foundation of the new website
- 【sdx62】WCN685X将bdwlan.bin和bdwlan.txt相互转化操作方法
- GPS from getting started to giving up (XIII), receiver autonomous integrity monitoring (RAIM)
- Some problems about the use of char[] array assignment through scanf..
- C#实现水晶报表绑定数据并实现打印4-条形码
- 华为在多个行业同时出击,吓人的技术让欧美企业瑟瑟发抖
- MySQL related terms
- GPS from entry to abandonment (XVII), tropospheric delay
- AI 企业多云存储架构实践 | 深势科技分享
- Intelligent online customer service system source code Gofly development log - 2 Develop command line applications
猜你喜欢

美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断

Aggregate function with key in spark

Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1

GPS從入門到放弃(十三)、接收機自主完好性監測(RAIM)

Bat script learning (I)
![[MySQL] online DDL details](/img/7e/97098d7ed5802c446bbadaf7035981.png)
[MySQL] online DDL details

Broadcast variables and accumulators in spark

zabbix 代理服务器 与 zabbix-snmp 监控

Make menuconfig has a recipe for target 'menuconfig' failed error

Oracle control file and log file management
随机推荐
HDU 2008 数字统计
Solve project cross domain problems
Reset Mikrotik Routeros using netinstall
解决项目跨域问题
Sparkshuffle process and Mr shuffle process
搜素专题(DFS )
What is the RDD operator in spark
HDU 2008 digital statistics
MariaDb数据库管理系统的学习(一)安装示意图
GPS从入门到放弃(十九)、精密星历(sp3格式)
GPS从入门到放弃(十一)、差分GPS
[sciter bug] multi line hiding
Unity3D学习笔记6——GPU实例化(1)
Run the deep network on PI and Jetson nano, and the program is killed
GPS from entry to abandonment (XVII), tropospheric delay
Huawei has launched attacks in many industries at the same time, and its frightening technology has made European and American enterprises tremble
anaconda安装第三方包
How does the uni admin basic framework close the creation of super administrator entries?
Maximum product of three numbers in question 628 of Li Kou
Is it important to build the SEO foundation of the new website