Skip to main content

883.三维体投影面积

思路

  • xy:grid[i][j] > 0 就加1
  • yz:按列找最大值
  • zx:按行找最大值

代码

class Solution {
public:
int projectionArea(vector<vector<int>>& grid) {
// xy
int xy = 0;
for (int i = 0; i < grid.size(); i++) {
for (int j = 0; j < grid[0].size() ;j++ ) {
if (grid[i][j] > 0) xy ++;
}
}

int yz = 0;
for (int i = 0; i < grid[0].size(); i++) {
int myz = 0;
for (int j = 0; j < grid.size(); j++) {
myz = max(myz, grid[j][i]);
}
yz += myz;
}

int zx = 0;
for (int i =0 ; i < grid.size(); i++) {
int mzx = 0;
for (int j = 0; j < grid[0].size(); j++) {
mzx = max(mzx, grid[i][j]);
}
zx += mzx;
}
return xy + yz + zx;
}
};