Skip to content

Commit

Permalink
Finish LeetCode3195.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiser-Yang committed Sep 12, 2024
1 parent cf1ff1c commit 8c0b241
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LeetCode/LeetCode3195.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// problem statement: https://leetcode.cn/problems/find-the-minimum-area-to-cover-all-ones-i/

#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
int minimumArea(vector<vector<int>>& grid) {
int l = numeric_limits<int>::max(), r = numeric_limits<int>::min(), u = numeric_limits<int>::max(), d = numeric_limits<int>::min();
for (int i = 0; i < grid.size(); i++) {
for (int j = 0; j < grid[i].size(); j++) {
if (grid[i][j] == 0) { continue; }
l = min(l, j);
r = max(r, j);
u = min(u, i);
d = max(d, i);
}
}
return (r - l + 1) * (d - u + 1);
}
};

0 comments on commit 8c0b241

Please sign in to comment.