Given a grid, return the number of islands.
Asked in the Coding stage. An island is a group of horizontally or vertically adjacent cells containing 1, surrounded by water cells containing 0. Diagonal cells are not connected.
Implement def num_islands(grid):. grid is a non-empty list of equal-length lists containing only 0 and 1. Return the island count as an integer. You may modify grid.
def num_islands(grid):