leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

3195.cpp (723B)


      1 static const auto _ = []() {
      2     std::ios_base::sync_with_stdio(false);
      3     std::cout.tie(nullptr);
      4     std::cin.tie(nullptr);
      5     return true;
      6 }();
      7 
      8 class Solution {
      9   public:
     10     int minimumArea(const vector<vector<int>> &grid) const {
     11         int minix = INT_MAX, maxix = INT_MIN;
     12         int miniy = INT_MAX, maxiy = INT_MIN;
     13 
     14         for (int i = 0; i < size(grid); i++) {
     15             for (int j = 0; j < size(grid[0]); j++) {
     16                 if (!grid[i][j]) continue;
     17                 minix = min(minix, i);
     18                 maxix = max(maxix, i);
     19                 miniy = min(miniy, j);
     20                 maxiy = max(maxiy, j);
     21             }
     22         }
     23 
     24         return (maxix - minix + 1) * (maxiy - miniy + 1);
     25     }
     26 };