-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution892.cs
39 lines (33 loc) · 921 Bytes
/
Solution892.cs
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
30
31
32
33
34
35
36
37
38
39
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution892
{
/// <summary>
/// 892. Surface Area of 3D Shapes - Easy
/// <a href="https://leetcode.com/problems/surface-area-of-3d-shapes">See the problem</a>
/// </summary>
public int SurfaceArea(int[][] grid)
{
int n = grid.Length;
int result = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (grid[i][j] > 0)
{
result += 2 + grid[i][j] * 4;
}
if (i > 0)
{
result -= Math.Min(grid[i][j], grid[i - 1][j]) * 2;
}
if (j > 0)
{
result -= Math.Min(grid[i][j], grid[i][j - 1]) * 2;
}
}
}
return result;
}
}