Number of Islands
Hard · Graphs
The grid contains 1 for land and 0 for water. An island is a group of land cells connected horizontally or vertically (not diagonally).
Write a function countIslands that returns the number of islands. An empty grid has 0 islands.
Next: Shortest Path in a Grid