Flood fill算法是从一个区域中提取若干个连通的点与其他相邻区域区分开的经典算法。因为其思路类似洪水从一个区域扩散到所有能到达的区域而得名。在GNU Go和扫雷中,Flood Fill算法被用来计算需要被清除的区域。
https://www.educative.io/edpresso/what-is-the-flood-fill-algorithm
The flood fill algorithm is used to determine the properties of the area around a particular cell in a block. The algorithm is implemented in the bucket fill tool of the Microsoft Paint program(桶填充), which colors the similarly colored pixels, or cells, with another color.
//Flood fill algorithm implemented in Java
class Example {
public static int M=8;
public static int N=8;
static void floodFill(int [][] myScreen, int x, int y, int currColor, int newColor)
{
// Base cases
if (x < 0 || x >= Example.M || y < 0 || y >= Example.N)
return;
if (myScreen[x][y] != currColor)
return;
if (myScreen[x][y] == currColor