|
| 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 "shadow" 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> </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 ("shadows") 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> </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 <= n <= 50</code></li> |
| 40 | + <li><code>0 <= grid[i][j] <= 50</code></li> |
| 41 | +</ul> |
0 commit comments