Medium

Quiz

#114 Flatten Binary Tree to Linked List

APPROACH

Rearrange the binary tree rooted at root into an in-place linked list:

- Reuse the same TreeNode class: the right pointer links to the next node and the left pointer must always be null.

- The resulting order must follow a pre-order traversal of the original tree.

Example 1:

Input: root = [1,2,5,3,4,null,6]
Output: [1,null,2,null,3,null,4,null,5,null,6]

Example 2:

Input: root = []
Output: []

Example 3:

Input: root = [0]
Output: [0]
1 of 4
1:00

What is the optimal approach for this problem?