|
| 1 | +<p>You are given an <code>m x n</code> matrix of characters <code>box</code> representing a side-view of a box. Each cell of the box is one of the following:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>A stone <code>'#'</code></li> |
| 5 | + <li>A stationary obstacle <code>'*'</code></li> |
| 6 | + <li>Empty <code>'.'</code></li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>The box is rotated <strong>90 degrees clockwise</strong>, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity <strong>does not</strong> affect the obstacles' positions, and the inertia from the box's rotation <strong>does not </strong>affect the stones' horizontal positions.</p> |
| 10 | + |
| 11 | +<p>It is <strong>guaranteed</strong> that each stone in <code>box</code> rests on an obstacle, another stone, or the bottom of the box.</p> |
| 12 | + |
| 13 | +<p>Return <em>an </em><code>n x m</code><em> matrix representing the box after the rotation described above</em>.</p> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong class="example">Example 1:</strong></p> |
| 17 | + |
| 18 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/rotatingtheboxleetcodewithstones.png" style="width: 300px; height: 150px;" /></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> box = [["#",".","#"]] |
| 22 | +<strong>Output:</strong> [["."], |
| 23 | + ["#"], |
| 24 | + ["#"]] |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p><strong class="example">Example 2:</strong></p> |
| 28 | + |
| 29 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/rotatingtheboxleetcode2withstones.png" style="width: 375px; height: 195px;" /></p> |
| 30 | + |
| 31 | +<pre> |
| 32 | +<strong>Input:</strong> box = [["#",".","*","."], |
| 33 | + ["#","#","*","."]] |
| 34 | +<strong>Output:</strong> [["#","."], |
| 35 | + ["#","#"], |
| 36 | + ["*","*"], |
| 37 | + [".","."]] |
| 38 | +</pre> |
| 39 | + |
| 40 | +<p><strong class="example">Example 3:</strong></p> |
| 41 | + |
| 42 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/rotatingtheboxleetcode3withstone.png" style="width: 400px; height: 218px;" /></p> |
| 43 | + |
| 44 | +<pre> |
| 45 | +<strong>Input:</strong> box = [["#","#","*",".","*","."], |
| 46 | + ["#","#","#","*",".","."], |
| 47 | + ["#","#","#",".","#","."]] |
| 48 | +<strong>Output:</strong> [[".","#","#"], |
| 49 | + [".","#","#"], |
| 50 | + ["#","#","*"], |
| 51 | + ["#","*","."], |
| 52 | + ["#",".","*"], |
| 53 | + ["#",".","."]] |
| 54 | +</pre> |
| 55 | + |
| 56 | +<p> </p> |
| 57 | +<p><strong>Constraints:</strong></p> |
| 58 | + |
| 59 | +<ul> |
| 60 | + <li><code>m == box.length</code></li> |
| 61 | + <li><code>n == box[i].length</code></li> |
| 62 | + <li><code>1 <= m, n <= 500</code></li> |
| 63 | + <li><code>box[i][j]</code> is either <code>'#'</code>, <code>'*'</code>, or <code>'.'</code>.</li> |
| 64 | +</ul> |
0 commit comments