class Solution {
private:
int row, col, count;
vector<int> watersize;
public:
void dfs(vector<vector<int>>& land, int r, int c) {
if (r < 0 || c < 0 || r >= row || c >= col || land[r][c] != 0) return;
land[r][c] = 1;
count ;
dfs(land, r 1, c);
dfs(land, r - 1, c);
dfs(land, r, c 1);
dfs(land, r, c - 1);
dfs(land, r 1, c 1);
dfs(land, r - 1, c - 1);
dfs(land, r 1, c - 1);
dfs(land, r - 1, c 1);
}
vector<int> pondSizes(vector<vector<int>>& land) {
row = land.size();
col = land[0].size();
for (int i = 0; i < row; i )
for (int j = 0; j < col; j ) {
if (land[i][j] == 0) {
count = 0;
dfs(land, i, j);
watersize.push_back(count);
}
}
sort(watersize.begin(), watersize.end());
return watersize;
}
};