2
void colorFill(int[][] image, int sr, int sc, int sourceColor, int targetColor) {3
int m = image.length, n = image[0].length;5
if (sr >= 0 && sr < m && sc >= 0 && sc < n) {6
if ((image[sr][sc] != sourceColor) || (image[sr][sc] == targetColor)) return;8
image[sr][sc] = targetColor;9
colorFill(image, sr, sc - 1, sourceColor, targetColor); // left10
colorFill(image, sr, sc + 1, sourceColor, targetColor); // right11
colorFill(image, sr - 1, sc, sourceColor, targetColor); // up12
colorFill(image, sr + 1, sc, sourceColor, targetColor); // down16
public int[][] floodFill(int[][] image, int sr, int sc, int color) {17
int rows = image.length, cols = image[0].length;19
colorFill(image, sr, sc, image[sr][sc], color);