leetcode-733-图像渲染
题目描述:
dfs:
class Solution: def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]: initColor = image[sr][sc] if(initColor == newColor): return image m, n = len(image), len(image[0]) def dfs(image, x, y, newColor): if(x < 0 or x >= m or y < 0 or y >= n): return if(image[x][y] == initColor): image[x][y] = newColor for d in [[-1, 0], [1, 0], [0, -1], [0, 1]]: dfs(image, x + d[0], y + d[1], newColor) dfs(image, sr, sc, newColor) return image