54. Flood Fill

Starting from pixel (sr, sc), repaint it and every pixel connected to it (4-directionally) with the same original colour using color. Return the image.

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]]

Example 2

Input: image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0
Output: [[0,0,0],[0,0,0]]
Hint 1

DFS from the start pixel, only stepping onto pixels with the original colour.

Hint 2

If the new colour equals the old one, return immediately.

GraphDFSMatrix