题目:
题解:
void cleanLand(char** grid, int gridSize, int ColSize,int row,int column)
{if(grid[row][column] == '1'){//不等于1则清零grid[row][column] = '0';}else{//不等于1则返回return ;}int newRow;int newColumn;//上if(row != 0) //还能上{newRow = row - 1;cleanLand(grid,gridSize,ColSize,newRow,column);}if(row != gridSize - 1) //还能下{newRow = row + 1;cleanLand(grid,gridSize,ColSize,newRow,column);}if(column != 0) //还能左{newColumn = column - 1;cleanLand(grid,gridSize,ColSize,row,newColumn);}if(column != ColSize-1) //还能右{newColumn = column + 1;cleanLand(grid,gridSize,ColSize,row,newColumn);}//到最后
}int numIslands(char** grid, int gridSize, int* gridColSize)
{int row,column;int ReturnLand = 0; //传入的是字符型数组for(row = 0; row < gridSize ; row++) //行{ for(column = 0; column < gridColSize[row] ;column++ ) //列{if(grid[row][column] == '1'){//出现的岛屿cleanLand(grid, gridSize,gridColSize[row],row,column);ReturnLand++; }}}return ReturnLand;
}