C++ DFS Approach
\nclass Solution {\npublic:\n    void dfs(int i, int j, int n, vector<vector<int>> &newGrid){\n        if(i<0 || i>=n || j<0 || j>=n || newGrid[i][j]==1) return
```\nclass Solution {\npublic:\n    void dfs(int i, int j, int n, vector<vector<int>> &newGrid){\n        if(i<0 || i>=n || j<0 || j>=n || newGrid[i][j]==1) return;\n        newGrid[i][j]=1;\n        dfs(i,j+1,n,newGrid);\n        dfs(i,j-1,n,newGrid);\n        dfs(i+1,j,n,newGrid);\n        dfs(i-1,j,n,newGrid);\n    }\n    int regionsBySlashes(vector<string>& grid) {\n        int n=grid.size(),i,j,ans=0;\n        vector<vector<int>> newGrid(n*3, vector<int> (n*3,0));\n        for(i=0;i<n;i++)\n            for(j=0;j<n;j++)\n                if(grid[i][j]==\'/\')\n                    newGrid[i*3][j*3+2]=newGrid[i*3+1][j*3+1]=newGrid[i*3+2][j*3]=1;\n                else if(grid[i][j]==\'\\\\\')\n                    newGrid[i*3][j*3]=newGrid[i*3+1][j*3+1]=newGrid[i*3+2][j*3+2]=1;\n        for(i=0;i<n*3;i++)\n            for(j=0;j<n*3;j++)\n                if(newGrid[i][j]==0) dfs(i,j,n*3,newGrid), ans++;\n        return ans;\n    }\n};\n```
[]