//深度优先 void dfs(int** image,int row,int col,int x,int y,int start,int newColor){ if (x<0 || x>=row || y<0 || y>=col || image[x][y] != start) return; image[x][y]=newColor; dfs(image,row,col,x+1,y,start,newColor); dfs(image,row,col,x-1,y,start,newColor); dfs(image,row,col,x,y+1,start,newColor); dfs(image,row,col,x,y-1,start,newColor); } int** floodFill(int** image, int imageSize, int* imageColSize, int sr, int sc, int newColor, int* returnSize, int** returnColumnSizes){ *returnSize=imageSize; *returnColumnSizes=imageColSize; if (newColor != image[sr][sc]) dfs(image,imageSize,*imageColSize,sr,sc,image[sr][sc],newColor); return image; }