-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path883.cpp
More file actions
29 lines (28 loc) · 760 Bytes
/
883.cpp
File metadata and controls
29 lines (28 loc) · 760 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
25
26
27
28
29
class Solution {
public:
int projectionArea(vector<vector<int>>& grid) {
int n = grid.size();
int res = 0;
// xy
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (grid[i][j] > 0) res++;
}
}
for (int i = 0; i < n; ++i) {
int maxValue = 0;
for (int j = 0; j < n; ++j) {
maxValue = max(maxValue, grid[i][j]);
}
res += maxValue;
}
for (int j = 0; j < n; ++j) {
int maxValue = 0;
for (int i = 0; i < n; ++i) {
maxValue = max(maxValue, grid[i][j]);
}
res += maxValue;
}
return res;
}
};