其他分享
首页 > 其他分享> > 【leetcode】面试题 08.10. 颜色填充

【leetcode】面试题 08.10. 颜色填充

作者:互联网

 

void dfs(int** image, int imageSize, int colsize, int r, int c, int newColor, int initColor){
    if(r<0 || r>=imageSize || c<0 || c>=colsize || image[r][c]!=initColor || image[r][c]==newColor) return;
    image[r][c]=newColor;
    dfs(image,imageSize,colsize,r-1,c,newColor,initColor);
    dfs(image,imageSize,colsize,r+1,c,newColor,initColor);
    dfs(image,imageSize,colsize,r,c-1,newColor,initColor);
    dfs(image,imageSize,colsize,r,c+1,newColor,initColor);
}
int** floodFill(int** image, int imageSize, int* imageColSize, int sr, int sc, int newColor, int* returnSize, int** returnColumnSizes){
    dfs(image,imageSize,*imageColSize,sr,sc,newColor,image[sr][sc]);
    *returnSize=imageSize;
    (*returnColumnSizes)=imageColSize;
    return image;
}

 

标签:面试题,newColor,imageSize,colsize,int,image,08.10,dfs,leetcode
来源: https://www.cnblogs.com/ganxiang/p/14049982.html