200. Number of Islands
Source: https://leetcode.com/problems/number-of-islands/description/
Intuition
Traverse the grid array using DFS. Check every entry in the array and use count to store the number of island.
Approach
When we visit a cell in the grid, we set its value as '0', as when we encounter the cell with '0', we simply ignore it and visit next cell. The invalid case for DFS is 
row < 0 || row >= grid.lengthcol < 0 || col >= grid[0].lengthgrid[row][col] != '1'
Complexity
- Time complexity: \(O(R \times C)\), in the worst case, we need to visit every cell in the grid.
 
- Space complexity: \(O(R \times C)\), in the worst case, all cells in the grid are land cells, thus DFS will be called \(R\times C\) times