mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
21 lines
936 B
HTML
21 lines
936 B
HTML
<p>The data structure <code>TreeNode</code> is used for binary tree, but it can also used to represent a single linked list (where left is null, and right is the next node in the list). Implement a method to convert a binary search tree (implemented with <code>TreeNode</code>) into a single linked list. The values should be kept in order and the operation should be performed in place (that is, on the original data structure).</p>
|
|
|
|
|
|
|
|
<p>Return the head node of the linked list after converting.</p>
|
|
|
|
|
|
|
|
<p><b>Note: </b>This problem is slightly different from the original one in the book.</p>
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
<p><strong>Example: </strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input: </strong> [4,2,5,1,3,null,6,0]
|
|
|
|
<strong>Output: </strong> [0,null,1,null,2,null,3,null,4,null,5,null,6]
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Note: </strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>The number of nodes will not exceed 100000.</li>
|
|
|
|
</ul>
|
|
|