#C271. Binary Tree Inorder Traversal
Binary Tree Inorder Traversal
Binary Tree Inorder Traversal
Given a binary tree represented as a list in level order format where null
indicates a missing node, construct the binary tree and output its inorder traversal. The inorder traversal is defined recursively as follows:
\( \text{inorder}(node) = \begin{cases} [] & \text{if } node \text{ is null} \\ \text{inorder}(node.left) \; \textbf{concatenated with} \; [node.val] \; \textbf{concatenated with} \; \text{inorder}(node.right) & \text{otherwise} \end{cases} \)
Print the resulting traversal as a sequence of space-separated integers on a single line. If the tree is empty, output an empty line.
inputFormat
A single line containing a JSON array that represents the tree in level order. Use null
(without quotes) to denote an absent node. For example: [1,2,3,null,4,5].
outputFormat
A single line containing the inorder traversal of the tree as space-separated integers. If the tree is empty, output an empty line.## sample
[1,2,3,null,4,5]
2 4 1 5 3