#C6685. Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked List
Given the root of a binary tree, flatten the tree into a linked list in-place. The flattened tree should use the right child pointers to point to the next node in the list and set the left child pointers to null. The order of nodes in the linked list should follow the pre-order traversal of the tree.
For example, a tree represented in level order as 1 2 5 3 4 null 6
should be transformed into a linked list represented as 1 2 3 4 5 6
.
inputFormat
A single line containing the level-order traversal of the binary tree. Each value is separated by spaces. Use an integer to represent a node's value and the string 'null' to represent an absent node. For example: 1 2 5 3 4 null 6
.
outputFormat
Output a single line containing the node values of the flattened tree (following the right child pointers) separated by spaces. For an empty tree, output an empty line.## sample
1 2 5 3 4 null 6
1 2 3 4 5 6