```/**
* 判断岛屿数量
* @param grid char字符型二维数组
* @param gridRowLen int grid数组行数
* @param gridColLen int* grid数组列数
* @return int整型
*
* C语言声明定义全局变量请加上static,防止重复定义
*/
//注意里面的数字是字符。
void p(char** grid,int gridRowlen,int *gridColLen,int i,int j)
{
if(i<0||j<0||i==gridRowlen||j==*gridColLen||grid[i][j]=='0')return ;
grid[i][j]='0';
p(grid,gridRowlen,gridColLen,i-1,j);
p(grid,gridRowlen,gridColLen,i,j-1);
p(grid,gridRowlen,gridColLen,i+1,j);
p(grid,gridRowlen,gridColLen,i,j+1);
}
int solve(char** grid, int gridRowLen, int* gridColLen ) {
// write code here
int count=0;
for(int i=0;i<gridRowLen;i++)
{
for(int j=0;j<*gridColLen;j++)
{
if(grid[i][j]=='1')
{
p(grid,gridRowLen,gridColLen,i,j);
count++;
}
}
}
return count;
}