Example 1
Input
image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Output
[[2,2,2],[2,2,0],[2,0,1]]
Loading CodeSprint...
/problems/flood-fill
Starting from one cell in an image grid, replace that cell and every four-directionally connected cell with the same original color. Return the updated grid.
Implement this function and return the result. CodeSprint supplies each test case automatically.
floodFill(image, sr, sc, color) → number[][]Input
image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2
Output
[[2,2,2],[2,2,0],[2,0,1]]
Input
image = [[0,0,0]], sr = 0, sc = 0, color = 0
Output
[[0,0,0]]
Constraints
1 <= image rows, columns <= 100 0 <= image[r][c], color <= 255 The starting coordinates are inside the grid.