Description
Given an image represented as a 2D array of integers, and a starting pixel (sr, sc), perform a flood fill with newColor from that starting pixel.
Examples
Input:
image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2Output:
[[2,2,2],[2,2,0],[2,0,1]]Explanation:
Fill from center.
Input:
image = [[1]], sr = 0, sc = 0, color = 2Output:
[[2]]Explanation:
The single pixel at (0,0) has value 1 and is changed to color 2.
Input:
image = [[0,1,0,2],[1,0,1,2],[0,1,0,2]], sr = 0, sc = 1, color = 3Output:
[[0,3,0,2],[3,0,3,2],[0,3,0,2]]Explanation:
Fill starts from top-middle position (0,1) with value 1. All connected pixels with value 1 form a diagonal pattern and get filled with color 3, while pixels with values 0 and 2 remain unchanged.
Constraints
- •
1 ≤ m, n ≤ 50