-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3195.cpp
More file actions
24 lines (24 loc) · 695 Bytes
/
3195.cpp
File metadata and controls
24 lines (24 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
int minimumArea(vector<vector<int>>& grid) {
int m = grid.size();
int n = grid[0].size();
int left = INT_MAX;
int right = INT_MIN;
int top = INT_MAX;
int bottom = INT_MIN;
int count = 0;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (grid[i][j] != 1) continue;
left = min(j, left);
right = max(j, right);
top = min(i, top);
bottom = max(i, bottom);
count++;
}
}
if (!count) return 0;
return (right - left + 1) * (bottom - top + 1);
}
};