1
class Solution {
2
public:
3
int projectionArea(vector<vector<int>> &grid) {
4
int res = 0;
5
// X-Y ( top )
6
for (int i = 0; i < grid.size(); i++) {
7
for (int j = 0; j < grid[0].size(); j++) {
8
if (grid[i][j]) // if some cubes are present it is seen as of area 1
9
// from top
10
res++;
11
}
12
}
13

14
// Z-X ( front )
15
for (int i = 0; i < grid.size(); i++) {
16
int m = grid[i][0];
17
for (int j = 1; j < grid[0].size(); j++) {
18
m = max(m, grid[i][j]); // from front, the tower with heightest height
19
// can only be seen in column
20
}
21
res += m;
22
}
23

24
// Z-Y ( side )
25
for (int j = 0; j < grid[0].size(); j++) {
26
int m = grid[0][j];
27
for (int i = 1; i < grid.size(); i++) {
28
m = max(m, grid[i][j]); // // from side, the tower with heightest height
29
// can only be seen in row
30
}
31
res += m;
32
}
33
return res;
34
}
35
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0