Skip to content

Commit e502af0

Browse files
Create README - LeetHub
1 parent e004db4 commit e502af0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<h2>114. Flatten Binary Tree to Linked List</h2><h3>Medium</h3><hr><div><p>Given the <code>root</code> of a binary tree, flatten the tree into a "linked list":</p>
2+
3+
<ul>
4+
<li>The "linked list" should use the same <code>TreeNode</code> class where the <code>right</code> child pointer points to the next node in the list and the <code>left</code> child pointer is always <code>null</code>.</li>
5+
<li>The "linked list" should be in the same order as a <a href="https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR" target="_blank"><strong>pre-order</strong><strong> traversal</strong></a> of the binary tree.</li>
6+
</ul>
7+
8+
<p>&nbsp;</p>
9+
<p><strong>Example 1:</strong></p>
10+
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/14/flaten.jpg" style="width: 500px; height: 226px;">
11+
<pre><strong>Input:</strong> root = [1,2,5,3,4,null,6]
12+
<strong>Output:</strong> [1,null,2,null,3,null,4,null,5,null,6]
13+
</pre>
14+
15+
<p><strong>Example 2:</strong></p>
16+
17+
<pre><strong>Input:</strong> root = []
18+
<strong>Output:</strong> []
19+
</pre>
20+
21+
<p><strong>Example 3:</strong></p>
22+
23+
<pre><strong>Input:</strong> root = [0]
24+
<strong>Output:</strong> [0]
25+
</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
32+
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
33+
</ul>
34+
35+
<p>&nbsp;</p>
36+
<strong>Follow up:</strong> Can you flatten the tree in-place (with <code>O(1)</code> extra space)?</div>

0 commit comments

Comments
 (0)