🔥C++ ✅✅ Best Solution ( 🔥 DFS 🔥 ) Easy to Understand💯💯 ⬆⬆⬆
Intuition\n Describe your first thoughts on how to solve this problem. \nDFS\n\n\n# Code\n\nclass Solution {\npublic:\n    \n    int solve(vector<vector<int>>& 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDFS\n\n\n# Code\n```\nclass Solution {\npublic:\n    \n    int solve(vector<vector<int>>& grid, vector<vector<bool>>& visited, int r, int c) {\n        visited[r][c] = true;\n        int  cnt = grid[r][c], n = grid.size(), m = grid[0].size();\n        \n        if(c+1<m && grid[r][c+1] && !visited[r][c+1])   {\n            cnt += solve(grid, visited, r, c+1);\n        }\n        \n        if(c-1>=0 && grid[r][c-1] && !visited[r][c-1])  {\n            cnt += solve(grid, visited, r, c-1);\n        }\n            \n        if(r+1<n && grid[r+1][c] && !visited[r+1][c])   {\n            cnt += solve(grid, visited, r+1, c);\n        }\n            \n        if(r-1>=0 && grid[r-1][c] && !visited[r-1][c])  {\n            cnt += solve(grid, visited, r-1, c);\n        }\n            \n        return cnt;\n    }\n    \n    int findMaxFish(vector<vector<int>>& grid) {\n        int maxi = 0, n = grid.size(), m = grid[0].size();\n        vector<vector<bool>> visited(n, vector<bool>(m, false));\n        \n        for(int i=0; i<n; i++)  for(int j=0; j<m; j++) \n                // if it is water cell and not visited the call the dfs function to calculate the total fish and compare with the maximum\n                if(grid[i][j] && !visited[i][j])   {\n                    int x = solve(grid, visited, i,  j);\n                    maxi = max(maxi, x);\n                }\n        return maxi;\n    }\n};\n```
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Recursion', 'C++']