733. 图像渲染_简单_矩阵
class Solution { public int[][] floodFill(int[][] image, int sr, int sc, int newColor) { int [][]foot = new int[image.length][image[0].length]; deleteIslands(sr,sc,newColor,image[sr][sc],image,foot); return image; } int deleteIslands(int i,int j,int newColor,int oldColor,int [][]grid,int [][]foot){ foot[i][j] =1; if(grid[i][j] != oldColor) return 0; else{ grid[i][j] = newColor; if(i<grid.length-1 && foot[i+1][j]==0 && grid[i+1][j]==oldColor){ deleteIslands(i+1,j, newColor,oldColor,grid,foot); } if(j<grid[0].length-1 && foot[i][j+1]==0 && grid[i][j+1]==oldColor){ deleteIslands(i,j+1, newColor,oldColor,grid,foot); } if(i>0 && foot[i-1][j]==0 && grid[i-1][j]==oldColor){ deleteIslands(i-1,j,newColor,oldColor, grid,foot); } if(j>0 && foot[i][j-1]==0 && grid[i][j-1]==oldColor){ deleteIslands(i,j-1,newColor,oldColor, grid,foot); } return 0; } } }
作者:你的雷哥
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。