Python 3   ||   8 lines, dfs   ||   T/S: 72% / 48%
\nclass Solution:\n    def findMaxFish(self, grid: List[List[int]]) -> int:\n\n        def dfs(r: int,c: int) -> int:\n\n            if (r,c) not in unseen:retu
```\nclass Solution:\n    def findMaxFish(self, grid: List[List[int]]) -> int:\n\n        def dfs(r: int,c: int) -> int:\n\n            if (r,c) not in unseen:return 0\n\n            unseen.remove((r,c))\n            return grid[r][c] + dfs(r+1,c)+dfs(r,c+1)+dfs(r-1,c)+dfs(r,c-1)\n            \n\n        m, n, ans = len(grid), len(grid[0]), 0\n        unseen = {(i,j) for i,j in product(range(m),range(n))\n                                                if grid[i][j]}\n        while unseen: ans = max(ans,dfs(*min(unseen)))\n\n        return ans \n```\n[https://leetcode.com/problems/maximum-number-of-fish-in-a-grid/submissions/1292976476/](https://leetcode.com/problems/maximum-number-of-fish-in-a-grid/submissions/1292976476/)\n\nI could be wrong, but I think that time complexity is *O*(*MN*) and space complexity is *O*(*MN*), in which *M*, *N* ~ `m`,`n`.
['Python3']