static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int maxAreaOfIsland(vector<vector<int>>& grid)
{
int x=grid.size();
int y=grid[].size();
int res=;
for(int i=;i<x;i++)
{
for(int j=;j<y;j++)
{
res=max(res,countarea(grid,i,j));
}
}
return res;
} int countarea(vector<vector<int>> &grid,int i,int j)
{
int szx=grid.size();
int szy=grid[].size();
int count=;
if(grid[i][j]==)
{
count++;
grid[i][j]=;
if(valid(i-,j,szx,szy)) count+=countarea(grid,i-,j);
if(valid(i,j-,szx,szy)) count+=countarea(grid,i,j-);
if(valid(i+,j,szx,szy)) count+=countarea(grid,i+,j);
if(valid(i,j+,szx,szy)) count+=countarea(grid,i,j+);
return count;
}
return ;
} bool valid(int i,int j,int szx,int szy)
{
return i>=&&i<szx&&j>=&&j<=szy;
} };
递归,问题不大