Given the matrix M [r] [c] filled with zeros and ones. Zero - the sea, 1 - land. An island is land, surrounded by the sea in columns or in a row. The island cannot be inside the island.
The task is to find the number of islands.
Example:
In
[[0, 1, 1],
[1, 0, 1],
[0, 1, 0]]
Out
3
In
[[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 1, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]]
Out
one
In
[[1, 0, 1],
[0, 1, 1]]
Out
2
In
[[1, 1, 1],
[1, 0, 1],
[1, 0, 1]]
Out
one
Question: what algorithms solve a similar problem, or ideas to solve this problem.
- 2careercup.com/question?id=5708658983829504 - MaxU
- oneYou need to search for connected components of the graph. To do this, you can simply find all adjacent vertices by searching for width / depth. - VladD
|