(int[][] grid)
| 2 | int rows; |
| 3 | int cols; |
| 4 | public int findMaxFish(int[][] grid) { |
| 5 | rows = grid.length; |
| 6 | cols = grid[0].length; |
| 7 | int maxFishes=0; |
| 8 | //find max of all components |
| 9 | for(int i=0;i<rows;i++){ |
| 10 | for(int j=0;j<cols;j++){ |
| 11 | if(grid[i][j]!=0){ |
| 12 | maxFishes=Math.max(maxFishes, dfs(i,j,grid)); |
| 13 | } |
| 14 | } |
| 15 | } |
| 16 | return maxFishes; |
| 17 | } |
| 18 | public int dfs(int r, int c, int grid[][]){ |
| 19 | //base case |
| 20 | //out of the matrix |