mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			65 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given an <code>m x n</code> matrix of characters <code>boxGrid</code> representing a side-view of a box. Each cell of the box is one of the following:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>A stone <code>'#'</code></li>
 | 
						|
	<li>A stationary obstacle <code>'*'</code></li>
 | 
						|
	<li>Empty <code>'.'</code></li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<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>
 | 
						|
 | 
						|
<p>It is <strong>guaranteed</strong> that each stone in <code>boxGrid</code> rests on an obstacle, another stone, or the bottom of the box.</p>
 | 
						|
 | 
						|
<p>Return <em>an </em><code>n x m</code><em> matrix representing the box after the rotation described above</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/rotatingtheboxleetcodewithstones.png" style="width: 300px; height: 150px;" /></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> boxGrid = [["#",".","#"]]
 | 
						|
<strong>Output:</strong> [["."],
 | 
						|
         ["#"],
 | 
						|
         ["#"]]
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/rotatingtheboxleetcode2withstones.png" style="width: 375px; height: 195px;" /></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> boxGrid = [["#",".","*","."],
 | 
						|
              ["#","#","*","."]]
 | 
						|
<strong>Output:</strong> [["#","."],
 | 
						|
         ["#","#"],
 | 
						|
         ["*","*"],
 | 
						|
         [".","."]]
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/rotatingtheboxleetcode3withstone.png" style="width: 400px; height: 218px;" /></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> boxGrid = [["#","#","*",".","*","."],
 | 
						|
              ["#","#","#","*",".","."],
 | 
						|
              ["#","#","#",".","#","."]]
 | 
						|
<strong>Output:</strong> [[".","#","#"],
 | 
						|
         [".","#","#"],
 | 
						|
         ["#","#","*"],
 | 
						|
         ["#","*","."],
 | 
						|
         ["#",".","*"],
 | 
						|
         ["#",".","."]]
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>m == boxGrid.length</code></li>
 | 
						|
	<li><code>n == boxGrid[i].length</code></li>
 | 
						|
	<li><code>1 <= m, n <= 500</code></li>
 | 
						|
	<li><code>boxGrid[i][j]</code> is either <code>'#'</code>, <code>'*'</code>, or <code>'.'</code>.</li>
 | 
						|
</ul>
 |