class Solution:

```
def numIslands(self, grid):
"""
:type grid: List[List[str]]
:rtype: int
"""
if len(grid) == 0 or grid is None:
return 0
length = len(grid)
width = len(grid[0])
seen = {}
num_groups = 0
for i in xrange(0, length):
for j in xrange(0, width):
if ((i,j) not in seen and grid[i][j] == "1"):
num_groups += 1
self.floodFill(i, j, length, width, seen, grid)
return num_groups
def floodFill(self, i, j, length, width, seen, grid):
if i < 0 or j < 0 or i >= length or j >= width or (i, j) in seen or grid[i][j] != "1":
return
seen[(i,j)] = True
self.floodFill(i+1, j, length, width, seen, grid)
self.floodFill(i, j+1, length, width, seen, grid)
self.floodFill(i-1, j, length, width, seen, grid)
self.floodFill(i, j-1, length, width, seen, grid)
self.floodFill(i+1, j-1, length, width, seen, grid)
self.floodFill(i+1, j+1, length, width, seen, grid)
self.floodFill(i-1, j+ 1, length, width, seen, grid)
self.floodFill(i-1, j-1, length, width,seen, grid)
```