Skip to content

Commit b25732a

Browse files
authored
Create 1992. Find All Groups of Farmland (#461)
2 parents c0d9a2f + c8f6e16 commit b25732a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

1992. Find All Groups of Farmland

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> findFarmland(vector<vector<int>>& land) {
4+
vector<vector<int>> ans;
5+
int n = land.size(), m = land[0].size(), flag;
6+
7+
for(int i = 0; i < n; i++){
8+
for(int j = 0; j < m; j++){
9+
if(land[i][j] == 1 && ((i == 0 || land[i-1][j] == 0) && (j == 0 || land[i][j-1] == 0))){
10+
int i_ = i, j_ = j;
11+
while(i_ < n && land[i_][j_] == 1)
12+
i_++;
13+
i_--;
14+
while(j_ < m && land[i_][j_] == 1)
15+
j_++;
16+
j_--;
17+
18+
ans.push_back({i, j, i_, j_});
19+
j = j_;
20+
}
21+
}
22+
}
23+
return ans;
24+
}
25+
};

0 commit comments

Comments
 (0)