-
Notifications
You must be signed in to change notification settings - Fork 46
/
_883.java
36 lines (30 loc) · 836 Bytes
/
_883.java
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
/**
* LeetCode 887 - Projection Area of 3D Shapes
*/
public class _883 {
public int projectionArea(int[][] grid) {
int ans = 0;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[i].length; j++) {
if (grid[i][j] > 0) {
ans++;
}
}
}
for (int i = 0; i < grid.length; i++) {
int max = 0;
for (int j = 0; j < grid[i].length; j++) {
max = Math.max(max, grid[i][j]);
}
ans += max;
}
for (int j = 0; j < grid[0].length; j++) {
int max = 0;
for (int i = 0; i < grid.length; i++) {
max = Math.max(max, grid[i][j]);
}
ans += max;
}
return ans;
}
}