291. Flood Fill
You are given an image represented by an m x n grid of integers image, where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and color. Your task is to perform a flood fill on the image starting from the pixel image[sr][sc]. To perform a flood fill: begin with the starting pixel and change its color to color. Perform the same process for each pixel that is directly adjacent (4-directionally) and shares the same color as the starting pixel. Keep repeating this process until there are no more adjacent pixels of the original color. Return the modified image.
Examples
Input: [[1,1,1],[1,1,0],[1,0,1]] 1 1 2
Output: [[2,2,2],[2,2,0],[2,0,1]]
Explanation: The connected region of 1's around (1,1) becomes 2's.
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
Run checks all cases above. Submit evaluates all test cases.