Practice Construct String from Binary Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Serialize the binary tree in preorder using each node's integer value. Put the left-child representation in parentheses immediately after its parent, followed by the right-child representation in another pair. Omit parentheses for absent children, except that a node with a right child but no left child must include () before the right-child parentheses. Leaves contain only their value. Return the string without spaces.
Source: Construct String from Binary Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [1,2,3,4]
"1(2(4))(3)"
# Example 2
root = [1,2,3,null,4]
"1(2()(4))(3)"
Constraints
Related LeetCode Problems
Practice more problems similar to Construct String from Binary Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.