classSolution:deffloodFill(self, image: List[List[int]], sr:int, sc:int, newColor:int)-> List[List[int]]:
target = image[sr][sc]
m, n =len(image),len(image[0])
q = collections.deque([(sr, sc)])
image[sr][sc]= newColor
seen =set((sr, sc))while q:
row, col = q.popleft()for x, y in([row +1, col],[row -1, col],[row, col +1],[row, col -1]):if0<= x < m and0<= y < n and image[x][y]== target and(x, y)notin seen:
image[x][y]= newColor
q.append((x, y))
seen.add((x, y))return image