Skip to content

Commit d113649

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 18.1 MB (18.23%)
1 parent a6838ff commit d113649

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<p>You are given an <code>n x n</code> <code>grid</code> where we place some <code>1 x 1 x 1</code> cubes that are axis-aligned with the <code>x</code>, <code>y</code>, and <code>z</code> axes.</p>
2+
3+
<p>Each value <code>v = grid[i][j]</code> represents a tower of <code>v</code> cubes placed on top of the cell <code>(i, j)</code>.</p>
4+
5+
<p>We view the projection of these cubes onto the <code>xy</code>, <code>yz</code>, and <code>zx</code> planes.</p>
6+
7+
<p>A <strong>projection</strong> is like a shadow, that maps our <strong>3-dimensional</strong> figure to a <strong>2-dimensional</strong> plane. We are viewing the &quot;shadow&quot; when looking at the cubes from the top, the front, and the side.</p>
8+
9+
<p>Return <em>the total area of all three projections</em>.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/02/shadow.png" style="width: 800px; height: 214px;" />
14+
<pre>
15+
<strong>Input:</strong> grid = [[1,2],[3,4]]
16+
<strong>Output:</strong> 17
17+
<strong>Explanation:</strong> Here are the three projections (&quot;shadows&quot;) of the shape made with each axis-aligned plane.
18+
</pre>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> grid = [[2]]
24+
<strong>Output:</strong> 5
25+
</pre>
26+
27+
<p><strong class="example">Example 3:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> grid = [[1,0],[0,2]]
31+
<strong>Output:</strong> 8
32+
</pre>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Constraints:</strong></p>
36+
37+
<ul>
38+
<li><code>n == grid.length == grid[i].length</code></li>
39+
<li><code>1 &lt;= n &lt;= 50</code></li>
40+
<li><code>0 &lt;= grid[i][j] &lt;= 50</code></li>
41+
</ul>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def projectionArea(self, grid: List[List[int]]) -> int:
3+
xy = sum(val > 0 for row in grid for val in row)
4+
yz = sum(max(row) for row in grid)
5+
zx = sum(max(col) for col in zip(*grid))
6+
return xy + yz + zx

0 commit comments

Comments
 (0)