Skip to content

Commit dcbc62f

Browse files
committed
Added README.md file for Flatten Binary Tree to Linked List
1 parent eae8107 commit dcbc62f

File tree

1 file changed

+39
-0
lines changed
  • 114-flatten-binary-tree-to-linked-list

1 file changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2><a href="https://leetcode.com/problems/flatten-binary-tree-to-linked-list">Flatten Binary Tree to Linked List</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>Given the <code>root</code> of a binary tree, flatten the tree into a &quot;linked list&quot;:</p>
2+
3+
<ul>
4+
<li>The &quot;linked list&quot; 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 &quot;linked list&quot; 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 class="example">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>
12+
<strong>Input:</strong> root = [1,2,5,3,4,null,6]
13+
<strong>Output:</strong> [1,null,2,null,3,null,4,null,5,null,6]
14+
</pre>
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> root = []
20+
<strong>Output:</strong> []
21+
</pre>
22+
23+
<p><strong class="example">Example 3:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> root = [0]
27+
<strong>Output:</strong> [0]
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
<p><strong>Constraints:</strong></p>
32+
33+
<ul>
34+
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
35+
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
36+
</ul>
37+
38+
<p>&nbsp;</p>
39+
<strong>Follow up:</strong> Can you flatten the tree in-place (with <code>O(1)</code> extra space)?

0 commit comments

Comments
 (0)