56. Number of Islands

grid is a map of "1" (land) and "0" (water). An island is a group of land cells connected horizontally or vertically. Count the islands.

Example 1

Input: grid = [["1","1","0","0"],["1","0","0","1"],["0","0","1","1"]]
Output: 2

Example 2

Input: grid = [["0"]]
Output: 0
Hint 1

Every unvisited land cell you meet starts a new island.

Hint 2

Flood-fill (DFS or BFS) the whole island so you never count it again.

GraphDFSBFSMatrix