mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			27 lines
		
	
	
		
			809 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			809 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p>
 | 
						|
 | 
						|
<p>A <strong>leaf</strong> is a node with no children.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-tree.jpg" style="width: 207px; height: 293px;" />
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> root = [1,2,3,null,5]
 | 
						|
<strong>Output:</strong> ["1->2->5","1->3"]
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> root = [1]
 | 
						|
<strong>Output:</strong> ["1"]
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>The number of nodes in the tree is in the range <code>[1, 100]</code>.</li>
 | 
						|
	<li><code>-100 <= Node.val <= 100</code></li>
 | 
						|
</ul>
 |