Given a grid
grid of 0 and 1, where 1 is land. An island is surrounded by water and formed by connecting adjacent lands horizontally or vertically. Return the number of islands.Example 1
Input: grid = ["11110","11010","11000","00000"]
Output: 1
Explanation: All land in the upper part is connected, so there is one island.
Output: 1
Explanation: All land in the upper part is connected, so there is one island.
Example 2
Input: grid = ["11000","11000","00100","00011"]
Output: 3
Explanation: Separately: the upper-left block, the center cell, and the lower-right block.
Output: 3
Explanation: Separately: the upper-left block, the center cell, and the lower-right block.