class Solution {
public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
int a = image.length;//数组行数
int b = image[0].length;//数组列数
int oldColor = image[sr][sc];
if(image[sr][sc] != newColor ) {
image[sr][sc] = newColor;
if(sr - 1 >= 0 && image[sr -1 ][sc] == oldColor ) {
floodFill(image, sr - 1, sc, newColor);
}
if(sr + 1 < a && image[sr + 1 ][sc] == oldColor ) {
floodFill(image, sr + 1, sc, newColor);
}
if(sc - 1 >= 0 && image[sr][sc - 1] == oldColor) {
floodFill(image, sr, sc - 1, newColor);
}
if(sc + 1 < b && image[sr ][sc + 1] == oldColor) {
floodFill(image, sr, sc + 1, newColor);
}
}
return image;
}
}