题解 | #岛屿的最大面积#
岛屿的最大面积
https://www.nowcoder.com/practice/5568943d3a08403f932a5e54ec3ece71
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param grid int整型二维数组 # @return int整型 # class Solution: def maxAreaIsland(self , grid: List[List[int]]) -> int: # write code here ans=0 for i in range(len(grid)): for j in range(len(grid[0])): # print(self.visited) if(grid[i][j]==1): ans=max(ans,self.Core(grid,i,j)) return ans def Core(self,grid,row,col): if(row<0 or row>=len(grid) or col<0 or col>=len(grid[0]) or grid[row][col]==0): return 0 grid[row][col]=0 up=self.Core(grid,row+1,col) down=self.Core(grid,row-1,col) left=self.Core(grid,row,col+1) right=self.Core(grid,row,col-1) return up+down+left+right+1