Java Recursive O(N^2) DeepFirst Search (From String Array to 2D Array)
\nclass Solution {\n    public int regionsBySlashes(String[] grid) {\n        int [][] g = new int[grid.length*3][grid.length*3];\n        int regions = 0;\n   
```\nclass Solution {\n    public int regionsBySlashes(String[] grid) {\n        int [][] g = new int[grid.length*3][grid.length*3];\n        int regions = 0;\n        for (int i = 0; i < grid.length; i++){      // transform the string to 2D grid array\n            for (int j = 0; j < grid.length; j++) {\n                if (grid[i].charAt(j) == \'/\') \n                    g[i * 3][j * 3 + 2] = g[i * 3 + 1][j * 3 + 1] = g[i * 3 + 2][j * 3] = 1;\n                if (grid[i].charAt(j) == \'\\\\\') \n                    g[i * 3][j * 3] = g[i * 3 + 1][j * 3 + 1] = g[i * 3 + 2][j * 3 + 2] = 1;\n            }\n        }\n        for (int i = 0; i < g.length; i++){      // use the help function to count the regions\n            for (int j = 0; j < g.length; j++){\n                if (g[i][j] == 0){\n                    DeepFirstSearch(g, i, j);\n                    regions++;\n                }\n            }\n        }\n        return regions;\n    }\n    \n    public void DeepFirstSearch(int [][]g, int i, int j) {\n        if (i >= 0 && j >= 0 && i < g.length && j < g.length && g[i][j] == 0) {\n            g[i][j] = 1;\n            DeepFirstSearch(g, i - 1, j);\n            DeepFirstSearch(g, i + 1, j);\n            DeepFirstSearch(g, i, j - 1);\n            DeepFirstSearch(g, i, j + 1);\n        }\n    }\n}\n```
[]