【leetcode 每日打卡】1020. 飞地的数量
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)):
共有 0 条评论