【leetcode】图像渲染

 

//深度优先
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;
}

 

posted @ 2020-09-28 09:11  温暖了寂寞  阅读(135)  评论(0编辑  收藏  举报