```
int numIslands(vector<vector<char>> &grid)
{
int m = grid.size();
if(m <= 0)
return 0;
int n = grid[0].size();
int ret = 0;
for(int i=0; i<m; ++i)
{
for(int j=0; j<n; ++j)
{
if(grid[i][j] == '1')
{
++ret;
DFS(grid, i, j);
}
}
}
return ret;
}
void DFS(vector<vector<char>> &grid, int i, int j)
{
grid[i][j] = '0';
if(i > 0 && grid[i-1][j] == '1')
DFS(grid, i-1, j);
if(i < grid.size()-1 && grid[i+1][j] == '1')
DFS(grid, i+1, j);
if(j > 0 && grid[i][j-1] == '1')
DFS(grid, i, j-1);
if(j < grid[0].size()-1 && grid[i][j+1] == '1')
DFS(grid, i, j+1);
}
```