Flood Fill

You are given an image represented by a grid of integers where each element represents the pixel value. Starting from a specific pixel, perform a flood fill operation to change the pixel color and those connected vertically or horizontally, having the same original color, to a new color. The operation stops when no more adjacent pixels of the original color remain.

Constraints

  • m == image.length
  • n == image[i].length
  • 1 <= m, n <= 50
  • 0 <= image[i][j], color < 2^16
  • 0 <= sr < m
  • 0 <= sc < n
Saving… · 2 lines
class Solution:
def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:
Console

Click Run to execute sample tests.