标签:++ lse == vector tor code pre int amp
class Solution {
public:
int rec(vector<vector<int>>& grid, int i, int j){
if(i>=grid.size() || j>= grid[0].size()){
return 0;
}
if(grid[i][j] == 1){
grid[i][j] = 0;
return 1 + rec(grid, i+1, j) + rec(grid, i, j+1) + rec(grid, i-1, j) + rec(grid, i, j-1);
}
else{
return 0;
}
}
int maxAreaOfIsland(vector<vector<int>>& grid) {
int res=0;
for(int i=0;i<grid.size();i++){
for(int j=0;j<grid[0].size();j++){
if(grid[i][j] == 1){
grid[i][j] = 0;
res = max(res, 1 + rec(grid, i+1, j) + rec(grid, i, j+1));
}
}
}
return res;
}
};
标签:++ lse == vector tor code pre int amp
原文地址:https://www.cnblogs.com/theodoric008/p/9420446.html