给一副二维整数数组图像渲染
这里也可以用沉岛思想
判断一个位置的上下左右是否是新的颜色,是则换成旧的
public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
int a = image[sr][sc];
if(a != newColor){
search(image,sr,sc,a,newColor);
}
return image;
}
public void search(int[][] image,int i,int j,int a,int newColor){
if( i<0 || i==image.length || j<0 || j==image[0].length || image[i][j]!=a){
return;
}
image[i][j] = newColor;
search(image,i+1,j,a, newColor);
search(image,i-1,j,a, newColor);
search(image,i,j+1,a, newColor);
search(image,i,j-1,a, newColor);
}