1992.cpp (646B)
1 class Solution { 2 public: 3 vector<vector<int>> findFarmland(const vector<vector<int>> &land) { 4 const int n = land.size(), m = land[0].size(); 5 vector<vector<int>> res; 6 for (int i = 0; i < n; i++) { 7 for (int j = 0; j < m; j++) { 8 if (!land[i][j] || (i > 0 && land[i - 1][j]) || (j > 0 && land[i][j - 1])) continue; 9 int a = i, b = j; 10 while (a < n && land[a][j]) 11 a++; 12 while (b < m && land[i][b]) 13 b++; 14 res.push_back({i, j, a - 1, b - 1}); 15 } 16 } 17 return res; 18 } 19 };