You are given a 2D grid of 1's (land) and 0's (water).
Your task is to count the number of islands.
You may assume that:
1's) connected vertically and horizontally.Return an integer representing the total number of islands.
[ [1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1] ]
1
All land cells are connected, forming a single island.
[ [0, 1, 1], [1, 0, 0], [1, 0, 1] ]
3
There are three islands: {(0,1),(0,2)}, {(1,0),(2,0)}, and {(2,2)}.
[ [1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1] ]
1