深度优先遍历注意grid 中的0, 1 均为字符串 class Solution: def dfs(self, grid, i, j, rows, cols): if i < 0 or j < 0 or j >= cols or i >= rows: return if grid[i][j] != '1': return grid[i][j] = '2' self.dfs(grid, i + 1, j, rows, cols) self...