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