← All problems
Number of Islands
MediumDFS / BFS
Given a 2D grid of '1' (land) and '0' (water), return the number of islands. An island is land cells connected horizontally/vertically.
Examples
Input: [["1","1","0","0"],["1","1","0","0"],["0","0","1","0"],["0","0","0","1"]]
Output: 3
Hints
Solution
Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 3 test cases.