Number of Islands

Problem Given an m × n binary grid ('1' land, '0' water), count the number of islands formed by horizontally or vertically adjacent land.

Input / Output

  • Input: an m × n grid of '0'/'1'.
  • Output: the number of islands.

Constraints

  • 1 <= m, n <= 300.

Example

  • grid = [[1,1,0],[1,0,0],[0,0,1]] → 2.
added …
LeaderboardSalaryAccount