Given a 2-dimensional 2-color bitmap, write a function to implement flood fill, e.g. the bucket in MS Paint. Assume that the fill will only fill white pixels with black.
The function should take the following parameters:
- A 2D array of booleans representing the pixels in the bitmap
- The X and Y position of the start point for the fill
So for example, in Java:
public void floodFill(boolean[][] bitmap, int xStart, int yStart)
这道题本质上是经典的 Flood Fill(泛洪填充)问题:从给定起点出发,把所有与起点连通、且颜色为白色的像素改成黑色。解法通常使用 DFS 或 BFS,从起点向四个方向扩展,遇到越界、非白色像素或已经访问过的像素就停止。关键点是正确处理连通性和边界条件,避免重复遍历。
正文完