200. Number of Islands
作者:互联网
class Solution {
public int numIslands(char[][] grid) {
int count=0;
for(int i=0;i<grid.length;i++)
for(int j=0;j<grid[0].length;j++)
{
if(grid[i][j]=='1')
{
fill(i, j, grid);
count++;
}
}
return count;
}
private void fill(int i, int j, char[][] grid){
if(i<0||i>=grid.length||j<0||j>=grid[0].length||grid[i][j]!='1')
return;
grid[i][j]='2';
fill(i-1, j, grid);
fill(i+1, j, grid);
fill(i, j-1, grid);
fill(i, j+1, grid);
}
}
转载于:https://www.cnblogs.com/asuran/p/7734152.html
标签:200,www,int,Number,char,length,grid,Islands,fill 来源: https://blog.csdn.net/weixin_34205076/article/details/94140086