void dfs(int** image, int rowSize, int colSize, int r, int c, int newColor, int oldColor){
if (r<0 || c<0 || r>=rowSize || c>=colSize || image[r][c] == newColor || image[r][c] != oldColor ){
return;
}
image[r][c] = newColor;
dfs(image, rowSize, colSize, r-1, c, newColor, oldColor);
dfs(image, rowSize, colSize, r+1, c, newColor, oldColor);
dfs(image, rowSize, colSize, r, c-1, newColor, oldColor);
dfs(image, rowSize, colSize, r, c+1, newColor, oldColor);
}
int** floodFill(int** image, int imageSize, int* imageColSize, int sr, int sc, int newColor, int* returnSize, int** returnColumnSizes){
dfs(image, imageSize, imageColSize[0], sr, sc, newColor, image[sr][sc]);
*returnSize = imageSize;
*returnColumnSizes = imageColSize;
return image;
}
面试题 08.10. 颜色填充
最新推荐文章于 2024-07-12 18:12:33 发布