class Solution {
public:
int projectionArea(vector<vector<int>>& grid) {
int a[1000];
memset(a, 0, sizeof(a));
int sum = 0;
int howlong = 0;
for (vector<vector<int>>::iterator it = grid.begin(); it != grid.end();
++it) {
if ((*it).size() > howlong)howlong = (*it).size();
int maxn = 0;
for (int i = 0; i < (*it).size(); ++i) {
//top
if ((*it)[i] != 0)++sum;
//front
if ((*it)[i] > maxn)maxn = (*it)[i];
//side
if ((*it)[i] > a[i])a[i] = (*it)[i];
}
sum += maxn;
}
for (int i = 0; i < howlong; ++i)sum += a[i];
return sum;
}
};
883. Projection Area of 3D Shapes
最新推荐文章于 2020-02-24 22:19:13 发布