[Java] DFS solution with photo and comments
Main idea: use dfs to mark the regions.\nThe times that we call dfs in 3 nested for loop is answer, because each dfs will mark connected areas visited and in th
Main idea: **use dfs to mark the regions.**\n**The times that we call dfs in 3 nested for loop is answer, because each dfs will mark connected areas visited and in the for loop only when current (row,col,type) is NOT visited, we go in dfs.**\n![image](https://assets.leetcode.com/users/images/765a3358-d81d-413a-a067-1e46b304466b_1620600759.512461.png)\n```java\n    private int row;\n    private int col;\n    private String[] grid;\n    private boolean[][][] visited;\n\n    public int regionsBySlashes(String[] grid) {\n        this.grid = grid;\n        row = grid.length;\n        col = grid[0].length();\n        visited = new boolean[row][col][4];\n        int count = 0;\n        // foreach NOT visited row,col,type dfs and increase count\n        for (int i = 0; i < row; i++) {\n            for (int j = 0; j < col; j++) {\n                for (int k = 0; k < 4; k++) {\n                    if (!visited[i][j][k]) {\n                        dfs(i, j, k);\n                        ++count;\n                    }\n                }\n            }\n        }\n        return count;\n    }\n\n    private void dfs(int i, int j, int type) {\n        if (!inBound(i, j) || visited[i][j][type]) {\n            return;\n        }\n        visited[i][j][type] = true;\n        // go to next row,col\n        switch (type) {\n            case 0:\n                dfs(i - 1, j, 2);\n                break;\n            case 1:\n                dfs(i, j - 1, 3);\n                break;\n            case 2:\n                dfs(i + 1, j, 0);\n                break;\n            case 3:\n                dfs(i, j + 1, 1);\n                break;\n        }\n        // in the same row col\n        switch (type) {\n            case 0:\n                if (grid[i].charAt(j) != \'/\') {\n                    dfs(i, j, 3);\n                }\n                if (grid[i].charAt(j) != \'\\\\\') {\n                    dfs(i, j, 1);\n                }\n                break;\n            case 1:\n                if (grid[i].charAt(j) != \'/\') {\n                    dfs(i, j, 2);\n                }\n                if (grid[i].charAt(j) != \'\\\\\') {\n                    dfs(i, j, 0);\n                }\n                break;\n            case 2:\n                if (grid[i].charAt(j) != \'/\') {\n                    dfs(i, j, 1);\n                }\n                if (grid[i].charAt(j) != \'\\\\\') {\n                    dfs(i, j, 3);\n                }\n                break;\n            case 3:\n                if (grid[i].charAt(j) != \'/\') {\n                    dfs(i, j, 0);\n                }\n                if (grid[i].charAt(j) != \'\\\\\') {\n                    dfs(i, j, 2);\n                }\n                break;\n        }\n    }\n\n    private boolean inBound(int i, int j) {\n        return i >= 0 && i < row && j >= 0 && j < col;\n    }\n```
['Depth-First Search']