Striver's type DFS code. Easy to understand
First we need to construct the matrix that contains 0\'s and 1\'s in the form of the slashes present.\n\n\n\n(Image credits to the owner)\n\nNow we can clearly 
First we need to construct the matrix that contains 0\'s and 1\'s in the form of the slashes present.\n\n\n![image.png](https://assets.leetcode.com/users/images/b51dc06e-1d2a-49b7-8cc3-1d75b695a13a_1723263186.17174.png)\n(Image credits to the owner)\n\nNow we can clearly see that the 0\'s are divided into parts considering the 1\'s as the boundary.\n\n# Code\n```\nclass Solution {\npublic:\n    void dfs(int i, int j, vector<vector<int>>&mat, vector<vector<int>>&vis){\n        vis[i][j] = 1;\n        int n = mat.size(),m=mat[0].size();\n        int delr[] = {-1,0,1,0};\n        int delc[] = {0,1,0,-1};\n        for(int k=0; k<4; k++){\n            int nrow = i+delr[k], ncol=j+delc[k];\n            if(nrow<0 || nrow>=n || ncol<0 || ncol>=m || mat[nrow][ncol]!=0 \n            || vis[nrow][ncol]) continue;\n            dfs(nrow,ncol,mat,vis);\n        }\n    }\n    int regionsBySlashes(vector<string>& grid) {\n        int n = grid.size();\n        vector<vector<int>>mat(n*3,vector<int>(n*3,0));\n        for(int i=0; i<n; i++){\n            for(int j=0; j<n; j++){\n                if(grid[i][j]==\'/\'){\n                    mat[i*3][j*3+2] = 1;\n                    mat[i*3+1][j*3+1] = 1;\n                    mat[i*3+2][j*3] = 1;\n                }else if(grid[i][j]==\'\\\\\'){\n                    mat[i*3][j*3] = 1;\n                    mat[i*3+1][j*3+1] = 1;\n                    mat[i*3+2][j*3+2] = 1;\n                }\n            }\n        } // till here the correct matrix have beem constructed.\n        // Now apply dfs to find the number of different islands formed by the 0\'s.\n        int count = 0;\n        vector<vector<int>>vis(n*3,vector<int>(n*3,0));\n        for(int i=0; i<n*3; i++){\n            for(int j=0; j<n*3; j++){\n                if(mat[i][j]==0 && !vis[i][j]){\n                    count++;\n                    dfs(i,j,mat,vis);\n                }\n            }\n        }\n        return count;\n    }\n};\n```
['C++']