leetcode-dfs-695. 岛屿的最大面积
作者:互联网
class Solution { public: int maxAreaOfIsland(vector<vector<int>>& grid) { int maxarea = 0; int m = grid.size(); int n = grid[0].size(); if(m==0||n==0) return maxarea; for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ if(grid[i][j] == 1){ maxarea = max(maxarea, search(grid,i,j)); } } } return maxarea; } int search(vector<vector<int>>& grid,int i, int j){ int m = grid.size(); int n = grid[0].size(); if(i>=m||j>=n||i<0||j<0||grid[i][j]==0) return 0; grid[i][j] = 0; // 正好可以标记为0,代表访问过。 return 1+search(grid,i,j+1)+search(grid,i,j-1)+search(grid,i-1,j)+search(grid,i+1,j); } };
标签:search,return,695,int,dfs,grid,leetcode,maxarea,size 来源: https://www.cnblogs.com/ymec/p/15132721.html