- By-row traversal
void traverseByRow(int[][] grid) { for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; i++) { visit(grid[i][j]); } } }
- Strategy 1
- Idea
- When you don't know where is the starting point to start a search algorithm, just traverse by rows. If the current cell satisfy the critiera, just start BFS or DFS algorithm.
- Code example
void traverseByRow(int[][] grid) { for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; i++) { if (satisfy the criteria) { BFS() or DFS() } } } } - Question examples
- Idea
- Path
- Search
- Traversal
- Manipulation
- Calculation
- Island
- Number of Islands
- Get Size of Largest Island
- 1254 Number of Closed Islands
- 1905 Count Sub Islands
- 694 Number of Distinct Islands
- 695 Max Area of Island
- Other