Flatten Binary Tree to Linked List

Given a binary tree, return a linked list that is a "flattened" version of the tree.

The linked list still uses the same nodes as a normal binary tree, only the left subtree is always empty, and the right subtree always points to the next element in the linked list (or the empty tree).

The flattened tree represents the pre-order traversal of the tree.


  • tree: the binary tree to be flattened.


A tree representing the flattened binary tree.


Example 1:


1tree = <See explanation>

Output: <See explanation>


Input tree:

Flattened tree:

Note that this uses the binary tree structure to represent the linked list.

Try it yourself




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions