You are viewing a single comment's thread. Return to all comments →
int surfaceArea(vector>& grid) { int rows = grid.size(); int cols = grid[0].size(); int totalArea = 0;
for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { int height = grid[i][j]; totalArea += 2; if (i > 0) totalArea += max(0, height - grid[i - 1][j]); else totalArea += height; if (i < rows - 1) totalArea += max(0, height - grid[i + 1][j]); else totalArea += height; if (j > 0) totalArea += max(0, height - grid[i][j - 1]); else totalArea += height; if (j < cols - 1) totalArea += max(0, height - grid[i][j + 1]); else totalArea += height; } } return totalArea; // Return the total surface area
}
`
Seems like cookies are disabled on this browser, please enable them to open this website
3D Surface Area
You are viewing a single comment's thread. Return to all comments →
int surfaceArea(vector>& grid) { int rows = grid.size(); int cols = grid[0].size(); int totalArea = 0;
}
`