Given a boolean 2D matrix, find the number of islands.

Notice 0 is represented as the sea, 1 is represented as the island. If two 1 is adjacent, we consider them in the same island. We only consider up/down/left/right adjacent.

Example

Return `3` for the following graph.

``````[
[1, 1, 0, 0, 0],
[0, 1, 0, 0, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 1]
]
``````

## Solution

We can use an easy breadth-first search algorithm, which follows:

We search each cell of the matrix. If the cell is a land (a 1), we increment our count, and perform bread-first search (BFS) expansion of that land, which is represented by `bfs()` method.

During the BFS expansion, for every connected land cell, we mark that as visited, which is recorded by the `v[][]` array. The sole purpose of the `bfs()` is to mark the connected land cells. The reason we want to do this, is that in the later search, when a land is found, but it is part of an island we already visited, then we do not increment the count.