C++ DFS (Number of islands)
\nclass Solution {\npublic:\n    int x[4] = {-1, 0, 0, 1};\n    int y[4] = {0, -1, 1, 0};\n\n    bool isValid(int i, int j, int m, int n, vector<vector<int>>& g
```\nclass Solution {\npublic:\n    int x[4] = {-1, 0, 0, 1};\n    int y[4] = {0, -1, 1, 0};\n\n    bool isValid(int i, int j, int m, int n, vector<vector<int>>& grid) {\n        if (i >= 0 and i < m and j >= 0 and j < n and grid[i][j] == 0)\n            return true;\n        return false;\n    }\n\n    void dfs(int i, int j, int m, int n, vector<vector<bool>>& visited, vector<vector<int>>& grid) {\n        visited[i][j] = true;\n        for (int k=0; k<4; k++) {\n            if (isValid(i+x[k],j+y[k], m, n, grid)) {\n                if (!visited[i+x[k]][j+y[k]]) {\n                    dfs(i+x[k], j+y[k], m, n, visited, grid);\n                }\n            }\n        }\n    }\n\n    int ff(vector<string>& grid) {\n        // Step 1. Uplevel the grid\n        if (!grid.size()) return 0;\n        int m = grid.size()*3;\n        int n = grid[0].size()*3;\n        vector<vector<int>> newGrid(m, vector<int>(n, 0));\n        vector<vector<bool>> visited(m, vector<bool>(n, false));\n        // Step 2. Fill in the new grid\n        for (int i=0; i<grid.size(); i++) {\n            for (int j=0; j<grid[0].size(); j++) {\n                if (grid[i][j] == \'/\') {\n                    newGrid[i*3][j * 3 + 2] = 1;\n                    newGrid[i * 3 + 1][j * 3 + 1] = 1;\n                    newGrid[i * 3 + 2][j * 3] = 1;\n                }\n                else if (grid[i][j] == \'\\\\\') {\n                    newGrid[i * 3][j * 3] = 1;\n                    newGrid[i * 3 + 1][j * 3 + 1] = 1;\n                    newGrid[i * 3 + 2][j * 3 + 2] = 1;\n                }\n            }\n        }\n        // Step 3. Apply DFS from every single cell\n        int count = 0;\n        for (int i=0; i<m; i++) {\n            for (int j=0; j<n; j++) {\n                if (newGrid[i][j] == 0 and !visited[i][j]) {\n                    dfs(i, j, m, n, visited, newGrid);\n                    count++;\n                }\n            }\n        }\n        // Step 4. Return count\n        return count;\n    } \n\n    int regionsBySlashes(vector<string>& grid) {\n        return ff(grid);\n    }\n};\n```
['Depth-First Search', 'C', 'C++']