Skip to content

Latest commit

 

History

History
76 lines (70 loc) · 2.91 KB

File metadata and controls

76 lines (70 loc) · 2.91 KB

2D Array

Basic operations

Traverse

  • 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]);
            }
        }
    }
    

Search

Strategies

  • 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

Common topics

back to Problem_Categories

back to Problem_Categories