Easy Solution | JAVA | DFS
Intuition\nTo find the maximum fish a fisherman can obtain. The zero represent the land and the numbers represent the number of available fish.\n\n# Approach\n 
# Intuition\nTo find the maximum fish a fisherman can obtain. The zero represent the land and the numbers represent the number of available fish.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Initialize the maximum variable as global\n- Create a boolean matrix called visited to keep track on the visited grid.\n- Create a function dfs, it helps to move to adjacent cells in deep and stop if the grid is already visted or the land is reached.\n- Increase the max for eachs recursive call.\n- Update the maximum vairalbe for each dfs call from the findMaxFish() function.\n> Upvote\n---\n\n\n\n# Code\n```\nclass Solution {\n    public int max;\n    public int findMaxFish(int[][] grid) {\n        int rlen = grid.length;\n        int clen = grid[0].length;\n        int answer = 0;\n        boolean visited[][] = new boolean[rlen][clen];\n        for(int i=0;i<rlen;i++){\n            for(int j=0;j<clen;j++){\n                if(grid[i][j]!=0 && !visited[i][j]){\n                    max = 0;\n                    dfs(grid, rlen, clen,visited, i, j);\n                    answer = Math.max(max, answer );\n                }\n            }\n        }\n        return answer;\n    }\n    \n    public void dfs(int[][] grid, int rlen, int clen, boolean[][] visited, int i, int j){\n        if(i<0||i>=rlen||j<0||j>=clen||visited[i][j]||grid[i][j] == 0){\n            return;\n        }\n        visited[i][j] = true;\n        max +=grid[i][j];\n        dfs(grid, rlen, clen, visited, i+1, j);\n        dfs(grid, rlen, clen, visited, i-1, j);\n        dfs(grid, rlen, clen, visited, i, j+1);\n        dfs(grid, rlen, clen, visited, i, j-1);\n    }\n}\n```
['Depth-First Search', 'Java']