mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			995 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			995 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p>(1) Only one disk can be moved at a time.<br />
 | 
						|
 | 
						|
(2) A disk is slid off the top of one tower onto another tower.<br />
 | 
						|
 | 
						|
(3) A disk cannot be placed on top of a smaller disk.</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p>Write a program to move the disks from the first tower to the last using stacks.</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong>Example1:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
<strong> Input</strong>: A = [2, 1, 0], B = [], C = []
 | 
						|
 | 
						|
<strong> Output</strong>: C = [2, 1, 0]
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong>Example2:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
<strong> Input</strong>: A = [1, 0], B = [], C = []
 | 
						|
 | 
						|
<strong> Output</strong>: C = [1, 0]
 | 
						|
 | 
						|
</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong>Note:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<ol>
 | 
						|
 | 
						|
	<li><code>A.length <= 14</code></li>
 | 
						|
 | 
						|
</ol>
 | 
						|
 |